This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ 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]

[Patch] Improve basic_stringbuf::str()


Hi,

seems a nice improvement (probably, already hinted to by Nathan
some time ago, as often happens...)

Tested x86-linux, ok for mainline?

Paolo.

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

	* include/std/std_sstream.h (str()): Avoid constructing
	a basic_string temporary not only when it would turn out
	to be zero-sized but also when identical to the current
	_M_string buffer.
diff -prN libstdc++-v3-orig/include/std/std_sstream.h libstdc++-v3/include/std/std_sstream.h
*** libstdc++-v3-orig/include/std/std_sstream.h	Wed Apr 30 14:26:32 2003
--- libstdc++-v3/include/std/std_sstream.h	Thu May  1 11:22:45 2003
*************** namespace std
*** 140,153 ****
  	    // represents the size of the initial string used to
  	    // created the buffer, and may not be the correct size of
  	    // the current stringbuf internal buffer.
! 	    __size_type __len = _M_string.size();
! 	    __size_type __nlen = this->_M_out_lim - this->_M_out_beg;
! 	    if (__nlen)
! 	      {
! 		__len = std::max(__nlen, __len);
! 		__ret = __string_type(this->_M_out_beg, 
! 				      this->_M_out_beg + __len);
! 	      }
  	  }
  	return __ret;
        }
--- 140,151 ----
  	    // represents the size of the initial string used to
  	    // created the buffer, and may not be the correct size of
  	    // the current stringbuf internal buffer.
! 	    const __size_type __len = _M_string.size();
! 	    const __size_type __nlen = this->_M_out_lim
! 	                               - this->_M_out_beg;
! 	    if (__nlen > __len)
! 	      __ret = __string_type(this->_M_out_beg, 
! 				    this->_M_out_beg + __nlen);
  	  }
  	return __ret;
        }

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