This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] Improve basic_stringbuf::str()
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: libstdc++ at gcc dot gnu dot org
- Cc: Nathan Myers <ncm at cantrip dot org>
- Date: Thu, 01 May 2003 11:29:14 +0200
- Subject: [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;
}