This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] Minor tweaks to stringbuf
- From: Paolo Carlini <carlinip at tiscali dot it>
- To: "'gcc-patches at gcc dot gnu dot org'" <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 01 Oct 2004 11:25:02 +0200
- Subject: [v3] Minor tweaks to stringbuf
Hi,
noticed while working recently on larger issues. Tested x86-linux,
committed.
Paolo.
//////////////
2004-10-01 Paolo Carlini <pcarlini@suse.de>
* include/bits/sstream.tcc (seekpos): Minor rearrangement of two
conditionals consistently with seekoff.
* include/std/std_sstream.h (setbuf): Avoid a string temporary.
(_M_sync): Simplify a bit, clean-up comment.
diff -urN libstdc++-v3-orig/include/bits/sstream.tcc libstdc++-v3/include/bits/sstream.tcc
--- libstdc++-v3-orig/include/bits/sstream.tcc 2004-09-30 19:23:05.000000000 +0200
+++ libstdc++-v3/include/bits/sstream.tcc 2004-10-01 09:56:36.000000000 +0200
@@ -187,14 +187,14 @@
const bool __testout = (ios_base::out & this->_M_mode & __mode) != 0;
const char_type* __beg = __testin ? this->eback() : this->pbase();
- if (__beg)
+ if (__beg && (__testin || __testout))
{
_M_update_egptr();
- off_type __pos(__sp);
+ const off_type __pos(__sp);
const bool __testpos = 0 <= __pos
&& __pos <= this->egptr() - __beg;
- if ((__testin || __testout) && __testpos)
+ if (__testpos)
{
if (__testin)
this->gbump((__beg + __pos) - this->gptr());
diff -urN libstdc++-v3-orig/include/std/std_sstream.h libstdc++-v3/include/std/std_sstream.h
--- libstdc++-v3-orig/include/std/std_sstream.h 2004-09-29 23:14:41.000000000 +0200
+++ libstdc++-v3/include/std/std_sstream.h 2004-10-01 10:55:59.000000000 +0200
@@ -219,7 +219,7 @@
// things will quickly blow up.
// Step 1: Destroy the current internal array.
- _M_string = __string_type(__s, __n);
+ _M_string.assign(__s, __n);
// Step 2: Use the external array.
_M_sync(__s, 0, 0);
@@ -253,20 +253,19 @@
{
const bool __testin = this->_M_mode & ios_base::in;
const bool __testout = this->_M_mode & ios_base::out;
- const __size_type __len = _M_string.size();
+ char_type* __end = __base + _M_string.size();
if (__testin)
- this->setg(__base, __base + __i, __base + __len);
+ this->setg(__base, __base + __i, __end);
if (__testout)
{
this->setp(__base, __base + _M_string.capacity());
this->pbump(__o);
- // We need a pointer to the string end anyway, even when
- // !__testin: in that case, however, for the correct
- // functioning of the streambuf inlines all the get area
- // pointers must be identical.
+ // egptr() always tracks the string end. When !__testin,
+ // for the correct functioning of the streambuf inlines
+ // the other get area pointers are identical.
if (!__testin)
- this->setg(__base + __len, __base + __len, __base + __len);
+ this->setg(__end, __end, __end);
}
}