This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
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.\
Btw., the spec already allows ostream to call xsputn(), so there should be no need to avoid calling it as the patch does.
Paolo.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |