This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
std_sstream.h - patch
- To: Benjamin Kosnik <bkoz@cygnus.com>
- Subject: std_sstream.h - patch
- From: Ryszard Kabatek <rysio@rumcajs.chemie.uni-halle.de>
- Date: Tue, 25 May 1999 14:03:54 +0200 (CEST)
- cc: libstdc++@sourceware.cygnus.com
- Reply-To: Ryszard Kabatek <kabatek@chemie.uni-halle.de>
The attached patch contains two optimizations for basic_stringbuf<>:
1. In the default constructor I changed _M_str(__string_type()) to _M_str().
2. In setbuf I changed the return value type and I removed the
temporary __string_type object. Now if the new buffer length is smaller
than the old one no reallocation is necessary.
BTW. The basic_streambuf<>::setbuf in bits/std_streambuf.h
does not return any value if 'if (false)' occurs.
1999-05-25 Ryszard Kabatek <kabatek@chemie.uni-halle.de>
* bits/std_sstream.h:
basic_stringbuf<>::basic_stringbuf: fix.
basic_stringbuf<>::setbuf:
remove the temporary __string_type object,
remove the unnecessary dynymic_cast in the return value,
change the type of the returned value from __streambuf_type*
to basic_stringbuf<_CharT, _Traits, _Alloc>*.
Ryszard Kabatek
Martin-Luther University Halle-Wittenberg, Department of Physical Chemistry
Geusaer Str. 88, 06217 Merseburg, Germany
Tel. +49 3461 46 2487 (2466) Fax. +49 3461 46 2129
Index: bits/std_sstream.h
===================================================================
RCS file: /cvs/libstdc++/libstdc++/bits/std_sstream.h,v
retrieving revision 1.32
diff -c -2 -p -r1.32 std_sstream.h
*** std_sstream.h 1999/05/21 10:33:25 1.32
--- std_sstream.h 1999/05/25 11:45:20
*************** namespace std {
*** 60,64 ****
explicit
basic_stringbuf(ios_base::openmode __mode = ios_base::in | ios_base::out)
! : __streambuf_type(), _M_str(__string_type())
{
_M_mode = __mode;
--- 60,64 ----
explicit
basic_stringbuf(ios_base::openmode __mode = ios_base::in | ios_base::out)
! : __streambuf_type(), _M_str()
{
_M_mode = __mode;
*************** namespace std {
*** 104,114 ****
overflow(int_type __c = traits_type::eof());
! virtual __streambuf_type*
setbuf(char_type* __s, streamsize __n)
{
! __string_type __str(__s, __n);
! if (__str.size())
! this->str(__str);
! return dynamic_cast<__streambuf_type*> (this);
}
--- 104,115 ----
overflow(int_type __c = traits_type::eof());
! virtual basic_stringbuf<_CharT, _Traits, _Alloc>*
setbuf(char_type* __s, streamsize __n)
{
! if (__n) {
! _M_str.assign(__s, __n);
! this->sync();
! }
! return this;
}