[v3] libstdc++/38678

Martin Sebor sebor@roguewave.com
Fri Jan 2 00:51:00 GMT 2009


Paolo Carlini wrote:
> Hi,
>> FWIW, calling sbumpc() for each character is inefficient,
>> especially when the size of the internal buffer is much
>> less than the size of the buffer being stored into, such
>> as in the unbuffered case. I suggest calling
>> streambuf::xsgetn() directly instead, like so:
>>
>> +  template<typename _CharT, typename _Traits>
>>      basic_istream<_CharT, _Traits>&
>>      basic_istream<_CharT, _Traits>::
>>      read(char_type* __s, streamsize __n)
>> @@ -611,7 +627,7 @@
>>        ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);
>>        try
>>          {
>> -          _M_gcount = this->rdbuf()->sgetn(__s, __n);
>> +             typedef basic_streambuf<_CharT, _Traits> _Streambuf;
>> +          _M_gcount = this->rdbuf()->_Streambuf::xsgetn(__s, __n);
>>            if (_M_gcount != __n)
>>          __err |= (ios_base::eofbit | ios_base::failbit);
>>          }
>>
>> (This requires that basic_streambuf be granted friendship
>> of basic_istream.)
> Of course, and because of that I adopted the general strategy used
> already in many other places: when we can rely on friendship, we have
> control on it (that is, basic_streambuf<char> and
> basic_streambuf<wchar_t>, that is instantiations the user cannot provide
> replacement specializations for) I added a fast specialization relying
> on xsgetn / xsputn, otherwise, we have the slow generic version, using
> only the public members of the streambuf.\

Ah, I had missed that in the patch.

Btw., the spec already allows ostream to call xsputn(), so
there should be no need to avoid calling it as the patch does.

Martin


> 
> Paolo.



More information about the Libstdc++ mailing list