This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] Simplify basic_stringbuf::seekoff
- From: Paolo Carlini <pcarlini at unitus dot it>
- To: libstdc++ at gcc dot gnu dot org
- Cc: bkoz <bkoz at redhat dot com>
- Date: Fri, 30 May 2003 20:37:51 +0200
- Subject: [Patch] Simplify basic_stringbuf::seekoff
Hi,
this is the first of two patches affecting basic_stringbuf::seekoff
and seekpos (the other one is more substantial)
Consider, f.i., __endi: when it's actually used, in the last 'if',
it's always equal to _M_in_end; __newoffi, likewise, which depends
on __endi, is used only when __endi is assigned _M_in_end.
Overall, this saves 4 varibles and two 'if', doesn't seem to worsen
that much the clarity.
Tested x86-linux. Ok with you?
Paolo.
/////////
2003-05-30 Paolo Carlini <pcarlini@unitus.it>
* include/bits/sstream.tcc (seekoff): Remove four unnecessary
variables and two 'if', clean up.
diff -urN libstdc++-v3-orig/include/bits/sstream.tcc libstdc++-v3/include/bits/sstream.tcc
--- libstdc++-v3-orig/include/bits/sstream.tcc 2003-05-07 07:01:57.000000000 +0200
+++ libstdc++-v3/include/bits/sstream.tcc 2003-05-30 19:48:31.000000000 +0200
@@ -132,45 +132,32 @@
if (_M_string.capacity() && (__testin || __testout || __testboth))
{
char_type* __beg = __testin ? this->_M_in_beg : this->_M_out_beg;
- char_type* __curi = NULL;
- char_type* __curo = NULL;
- char_type* __endi = NULL;
- char_type* __endo = NULL;
-
- if (__testin || __testboth)
- {
- __curi = this->_M_in_cur;
- __endi = this->_M_in_end;
- }
- if (__testout || __testboth)
- {
- __curo = this->_M_out_cur;
- // Due to the resolution of DR169, ios_base::end
- // is this->_M_out_lim, not _M_out_end.
- __endo = this->_M_out_lim;
- }
off_type __newoffi = 0;
off_type __newoffo = 0;
if (__way == ios_base::cur)
{
- __newoffi = __curi - __beg;
- __newoffo = __curo - __beg;
+ __newoffi = this->_M_in_cur - __beg;
+ __newoffo = this->_M_out_cur - __beg;
}
else if (__way == ios_base::end)
{
- __newoffi = __endi - __beg;
- __newoffo = __endo - __beg;
+ __newoffi = this->_M_in_end - __beg;
+ // Due to the resolution of DR169, ios_base::end
+ // is this->_M_out_lim, not _M_out_end.
+ __newoffo = this->_M_out_lim - __beg;
}
if ((__testin || __testboth)
- && __newoffi + __off >= 0 && __endi - __beg >= __newoffi + __off)
+ && __newoffi + __off >= 0
+ && this->_M_in_end - __beg >= __newoffi + __off)
{
this->_M_in_cur = __beg + __newoffi + __off;
__ret = pos_type(__newoffi);
}
if ((__testout || __testboth)
- && __newoffo + __off >= 0 && __endo - __beg >= __newoffo + __off)
+ && __newoffo + __off >= 0
+ && this->_M_out_lim - __beg >= __newoffo + __off)
{
_M_move_out_cur(__newoffo + __off - (this->_M_out_cur - __beg));
__ret = pos_type(__newoffo);