[RFC/patch] Fixing libstdc++/11378 and, while at it... ;)

Jerry Quinn jlquinn@optonline.net
Wed Jul 2 12:39:00 GMT 2003


Paolo Carlini writes:
 > Hi,
[nice performance improvements deleted]
 > 
 > Comments appreciated!
 > 
 > Paolo.
 > 
 > ////////////
 > diff -urN libstdc++-v3-curr/include/std/std_fstream.h libstdc++-v3/include/std/std_fstream.h
 > --- libstdc++-v3-curr/include/std/std_fstream.h	2003-06-30 13:17:22.000000000 +0200
 > +++ libstdc++-v3/include/std/std_fstream.h	2003-07-02 04:32:49.000000000 +0200
 > @@ -399,8 +399,14 @@
 >        virtual streamsize
 >        xsputn(const char_type* __s, streamsize __n)
 >        {
 > -	_M_destroy_pback();
 > -	return __streambuf_type::xsputn(__s, __n);
 > +	streamsize __ret = 0;
 > +	const bool __testout = this->_M_mode & ios_base::out;
 > +	if(__testout && !_M_reading && this->_M_buf_size == 1

Should this be _M_buf_size >= 1?

 > +	   && __check_facet(_M_codecvt).always_noconv())

always_noconv() is another virtual.  The answer to this could be
cached in a bool.  That will avoid the __check_facet test and the
virtual call.

 > +	  __ret = _M_file.xsputn(reinterpret_cast<const char*>(__s), __n);
 > +	else
 > +	  __ret = __streambuf_type::xsputn(__s, __n);
 > +	return __ret;

Cool!  I started to look a bit at this since it also shows up in the
hot path for the integer output benchmark, but hadn't gotten very far.

Jerry



More information about the Libstdc++ mailing list