This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [v3] More libstdc++/8761 and 7076
- From: "B. Kosnik" <bkoz at nabi dot net>
- To: libstdc++ at gcc dot gnu dot org
- Cc: jlquinn at optonline dot net
- Date: Mon, 3 Feb 2003 11:25:01 -0600
- Subject: Re: [v3] More libstdc++/8761 and 7076
- References: <E18fZi7-0001q5-00@tiamat>
>When inserting chars and strings, we were calling basic_ostream::write(),
>which creates redundant sentry objects.
Yep. Nice.
>No regressions.
Confirmed.
>OK for 3.3 and mainline? I actually think it's safe for 3.2 as well, but
>won't have a huge impact.
This is safe for all branches.
>2003-02-03 Jerry Quinn <jlquinn@optonline.net>
>
> * ostream.tcc (_M_write): New.
> (basic_ostream::write): Use it.
> (operator<<(basic_ostream, _CharT)): Ditto.
> (operator<<(basic_ostream, char)): Ditto.
> (operator<<(basic_ostream, _CharT*)): Ditto.
> (operator<<(basic_ostream, char*)): Ditto.
> (operator<<(basic_ostream, basic_string)): Ditto.
Ok.
_M_write doesn't have to be at global scope, it can be a member
function. See below. Ok with these mods. Thoughts?
2003-02-03 Jerry Quinn <jlquinn@optonline.net>
* include/std/std_ostream.h (ostream::_M_write): Declare.
* ostream.tcc (ostream::_M_write): Define.
(basic_ostream::write): Use it.
(operator<<(basic_ostream, _CharT)): Ditto.
(operator<<(basic_ostream, char)): Ditto.
(operator<<(basic_ostream, _CharT*)): Ditto.
(operator<<(basic_ostream, char*)): Ditto.
(operator<<(basic_ostream, basic_string)): Ditto.
Index: include/bits/ostream.tcc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/bits/ostream.tcc,v
retrieving revision 1.32
diff -c -p -r1.32 ostream.tcc
*** include/bits/ostream.tcc 16 Jan 2003 20:30:23 -0000 1.32
--- include/bits/ostream.tcc 3 Feb 2003 17:23:56 -0000
***************
*** 1,6 ****
// ostream classes -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
--- 1,6 ----
// ostream classes -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
*************** namespace std
*** 388,394 ****
if (traits_type::eq_int_type(__put, traits_type::eof()))
this->setstate(ios_base::badbit);
}
! return *this;
}
template<typename _CharT, typename _Traits>
--- 388,394 ----
if (traits_type::eq_int_type(__put, traits_type::eof()))
this->setstate(ios_base::badbit);
}
! return *this;
}
template<typename _CharT, typename _Traits>
*************** namespace std
*** 397,407 ****
{
sentry __cerb(*this);
if (__cerb)
! {
! streamsize __put = this->rdbuf()->sputn(__s, __n);
! if ( __put != __n)
! this->setstate(ios_base::badbit);
! }
return *this;
}
--- 397,403 ----
{
sentry __cerb(*this);
if (__cerb)
! _M_write(__s, __n);
return *this;
}
*************** namespace std
*** 488,494 ****
&__c, __w, __len, false);
__len = __w;
}
! __out.write(__pads, __len);
__out.width(0);
}
catch(exception& __fail)
--- 484,490 ----
&__c, __w, __len, false);
__len = __w;
}
! __out._M_write(__pads, __len);
__out.width(0);
}
catch(exception& __fail)
*************** namespace std
*** 524,530 ****
&__c, __w, __len, false);
__len = __w;
}
! __out.write(__pads, __len);
__out.width(0);
}
catch(exception& __fail)
--- 520,526 ----
&__c, __w, __len, false);
__len = __w;
}
! __out._M_write(__pads, __len);
__out.width(0);
}
catch(exception& __fail)
*************** namespace std
*** 559,565 ****
__s = __pads;
__len = __w;
}
! __out.write(__s, __len);
__out.width(0);
}
catch(exception& __fail)
--- 555,561 ----
__s = __pads;
__len = __w;
}
! __out._M_write(__s, __len);
__out.width(0);
}
catch(exception& __fail)
*************** namespace std
*** 608,614 ****
__str = __pads;
__len = __w;
}
! __out.write(__str, __len);
__out.width(0);
}
catch(exception& __fail)
--- 604,610 ----
__str = __pads;
__len = __w;
}
! __out._M_write(__str, __len);
__out.width(0);
}
catch(exception& __fail)
*************** namespace std
*** 647,653 ****
__s = __pads;
__len = __w;
}
! __out.write(__s, __len);
__out.width(0);
}
catch(exception& __fail)
--- 643,649 ----
__s = __pads;
__len = __w;
}
! __out._M_write(__s, __len);
__out.width(0);
}
catch(exception& __fail)
*************** namespace std
*** 688,697 ****
__s = __pads;
__len = __w;
}
! streamsize __res = __out.rdbuf()->sputn(__s, __len);
__out.width(0);
- if (__res != __len)
- __out.setstate(ios_base::failbit);
}
return __out;
}
--- 684,691 ----
__s = __pads;
__len = __w;
}
! __out._M_write(__s, __len);
__out.width(0);
}
return __out;
}
Index: include/std/std_ostream.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/include/std/std_ostream.h,v
retrieving revision 1.5
diff -c -p -r1.5 std_ostream.h
*** include/std/std_ostream.h 21 Nov 2002 07:06:41 -0000 1.5
--- include/std/std_ostream.h 3 Feb 2003 17:23:57 -0000
***************
*** 1,6 ****
// Output streams -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
--- 1,6 ----
// Output streams -*- C++ -*-
! // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
*************** namespace std
*** 260,265 ****
--- 260,274 ----
*/
__ostream_type&
put(char_type __c);
+
+ // Core write functionality, without sentry.
+ void
+ _M_write(const char_type* __s, streamsize __n)
+ {
+ streamsize __put = this->rdbuf()->sputn(__s, __n);
+ if (__put != __n)
+ this->setstate(ios_base::badbit);
+ }
/**
* @brief Character string insertion.