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]

[v3] Improve basic_stringbuf::overflow


Hi,

tested x86-linux. Approved by Benjamin.

Paolo.

///////
2003-05-01  Paolo Carlini  <pcarlini@unitus.it>

	* include/bits/sstream.tcc (overflow): Instead of calling
	str(), then _M_string.reserve, thus copying the contents
	of the current buffer two times, just copy the latter in
	a temporary, then use the 'swap trick'.
diff -prN libstdc++-v3-orig/include/bits/sstream.tcc libstdc++-v3/include/bits/sstream.tcc
*** libstdc++-v3-orig/include/bits/sstream.tcc	Wed Apr 30 14:26:32 2003
--- libstdc++-v3/include/bits/sstream.tcc	Fri May  2 02:11:26 2003
*************** namespace std
*** 100,110 ****
        // Order these tests done in is unspecified by the standard.
        if (!__testput)
  	{
- 	  // Force-allocate, re-sync.
- 	  _M_string = this->str();
  	  // In virtue of DR 169 (TC) we are allowed to grow more than
  	  // one char. That's easy to implement thanks to the exponential
  	  // growth policy builtin into basic_string.
  	  _M_string.reserve(__len);
  	  _M_really_sync(const_cast<char_type*>(_M_string.data()),
  			 this->_M_in_cur - this->_M_in_beg, 
--- 100,114 ----
        // Order these tests done in is unspecified by the standard.
        if (!__testput)
  	{
  	  // In virtue of DR 169 (TC) we are allowed to grow more than
  	  // one char. That's easy to implement thanks to the exponential
  	  // growth policy builtin into basic_string.
+ 	  __string_type __tmp;
+ 	  __tmp.reserve(__len);
+ 	  __tmp.assign(_M_string.data(),
+ 		       this->_M_out_end - this->_M_out_beg);
+ 	  _M_string.swap(__tmp);
+ 	  // Just to be sure...
  	  _M_string.reserve(__len);
  	  _M_really_sync(const_cast<char_type*>(_M_string.data()),
  			 this->_M_in_cur - this->_M_in_beg, 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]