sstream.tcc (overflow): Instead of calling str()...
authorPaolo Carlini <pcarlini@unitus.it>
Fri, 2 May 2003 00:14:49 +0000 (02:14 +0200)
committerPaolo Carlini <paolo@gcc.gnu.org>
Fri, 2 May 2003 00:14:49 +0000 (00:14 +0000)
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'.

From-SVN: r66358

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/sstream.tcc

index cd55a6b5e018102a1a10f9183ddec93033e6d079..60d513755962d52e6a3f5f49d823984292dcb427 100644 (file)
@@ -1,3 +1,10 @@
+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'.
+
 2003-05-01  Paolo Carlini  <pcarlini@unitus.it>
 
        * include/std/std_sstream.h (str()): Revert the best of the
index 11751783722a62dcfeabdeffdf125c453a3ef56b..c09553127cc139c84a4682a257922fff6a630b48 100644 (file)
@@ -100,11 +100,15 @@ namespace std
       // 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.
+         __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,