This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[RFC] A mild "hack" for the string half of 15002
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Fri, 23 Apr 2004 15:56:10 +0200
- Subject: [RFC] A mild "hack" for the string half of 15002
Hi,
as explained so interestingly by Matt, for getline(istream, string) we
can't do incredibly cute things in the general case...
Therefore, for now, for 3.4.x definitely and usable in the general case,
I'm considering the below, which gives (600000 lines, 200 char long):
current
-------
3.190u 0.080s 0:03.28 99.6% 0+0k 0+0io 203pf+0w
vs
patched
-------
1.090u 0.100s 0:01.19 100.0% 0+0k 0+0io 204pf+0w
What do you think? Does it seem something we can live with, everything
considered? FWIW, we are already using a similar trick in basic_string
for the constructor from input_iterators.
(Regtested x86-linux)
Paolo.
//////////
diff -prN libstdc++-v3-curr/include/bits/istream.tcc libstdc++-v3/include/bits/istream.tcc
*** libstdc++-v3-curr/include/bits/istream.tcc Fri Apr 23 12:17:58 2004
--- libstdc++-v3/include/bits/istream.tcc Fri Apr 23 15:32:35 2004
*************** namespace std
*** 1103,1108 ****
--- 1103,1111 ----
try
{
__str.erase();
+ _CharT __buf[128];
+ _CharT* __s = __buf;
+
const __int_type __idelim = _Traits::to_int_type(__delim);
const __int_type __eof = _Traits::eof();
__streambuf_type* __sb = __in.rdbuf();
*************** namespace std
*** 1112,1121 ****
&& !_Traits::eq_int_type(__c, __eof)
&& !_Traits::eq_int_type(__c, __idelim))
{
! __str += _Traits::to_char_type(__c);
__c = __sb->snextc();
++__extracted;
}
if (_Traits::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
else if (_Traits::eq_int_type(__c, __idelim))
--- 1115,1131 ----
&& !_Traits::eq_int_type(__c, __eof)
&& !_Traits::eq_int_type(__c, __idelim))
{
! if (__s == __buf + sizeof(__buf) / sizeof(_CharT))
! {
! __str.append(__buf, sizeof(__buf) / sizeof(_CharT));
! __s = __buf;
! }
! *__s++ = _Traits::to_char_type(__c);
__c = __sb->snextc();
++__extracted;
}
+ __str.append(__buf, __s - __buf);
+
if (_Traits::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
else if (_Traits::eq_int_type(__c, __idelim))