This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] Again on __copy_streambufs
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: libstdc++ at gcc dot gnu dot org
- Cc: bkoz <bkoz at redhat dot com>
- Date: Sun, 27 Apr 2003 14:08:15 +0200
- Subject: [Patch] Again on __copy_streambufs
Hi,
I guess that for while this will be the last contribution
from me in this specific area. I'm quite happy with it, now ;)
The patch does two, mostly unrelated, things:
1- Remove any reference to _M_buf_size: this is incorrect
now, since basic_stringbuf doesn't use it, and isn't
useful anymore since the various in_avail/sync/interactive
troubles at the root of it have been fixed elsewhere.
2- When there is no room in the output buffer, instead of
copying 'til the end one char at the time in a loop try
to make room by calling overflow (thanks Nathan!).
Tested x86-linux + 27_io/objects by hand + a few sanity checks.
Ok for trunk?
Paolo.
/////////
2003-04-27 Paolo Carlini <pcarlini at unitus dot it>
* include/bits/streambuf.tcc (__copy_streambufs): Don't use
_M_buf_size (synced input is now correctly dealt with
elsewhere); when the output buffer is full don't fall back
to a snextc-sputc loop, call overflow instead.
diff -urN libstdc++-v3-orig/include/bits/streambuf.tcc libstdc++-v3/include/bits/streambuf.tcc
--- libstdc++-v3-orig/include/bits/streambuf.tcc 2003-04-26 20:42:26.000000000 +0200
+++ libstdc++-v3/include/bits/streambuf.tcc 2003-04-27 12:31:21.000000000 +0200
@@ -188,8 +188,6 @@
typedef typename _Traits::off_type off_type;
streamsize __ret = 0;
- const off_type __buf_size =
- __sbin->_M_buf_size > 0 ? __sbin->_M_buf_size : 1;
try
{
for (;;)
@@ -208,10 +206,9 @@
else
{
streamsize __charsread;
- const off_type __size = std::min(__buf_size,
- off_type(__sbout->_M_out_end
- - __sbout->_M_out_cur));
- if (__size > 1)
+ const off_type __size = __sbout->_M_out_end
+ - __sbout->_M_out_cur;
+ if (__size)
{
_CharT* __buf =
static_cast<_CharT*>(__builtin_alloca(sizeof(_CharT)
@@ -224,15 +221,15 @@
else
{
__xtrct = __charsread = 0;
- int_type __c = __sbin->sgetc();
- while (!_Traits::eq_int_type(__c, _Traits::eof()))
+ const int_type __c = __sbin->sgetc();
+ if (!_Traits::eq_int_type(__c, _Traits::eof()))
{
++__charsread;
- if (_Traits::eq_int_type(__sbout->sputc(_Traits::to_char_type(__c)),
+ if (_Traits::eq_int_type(__sbout->overflow(__c),
_Traits::eof()))
break;
++__xtrct;
- __c = __sbin->snextc();
+ __sbin->sbumpc();
}
}
__ret += __xtrct;