This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[v3] Fix libstdc++/15002 (continued again)
- From: Paolo Carlini <pcarlini at suse dot de>
- To: "'gcc-patches at gcc dot gnu dot org'" <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 25 Apr 2004 18:08:36 +0200
- Subject: [v3] Fix libstdc++/15002 (continued again)
Hi,
this one should be the last in the series, for now.
I'm quite happy with the improvement: on my P4-2400 (-O2), on
the two testcases in the PR:
3.4.0
-----
'streams' : 8.870u 0.100s 0:09.01 99.5% 0+0k 0+0io 206pf+0w
'streams2': 1.210u 0.100s 0:01.31 100.0% 0+0k 0+0io 203pf+0w
mainline
--------
'streams' : 1.080u 0.070s 0:01.15 100.0% 0+0k 0+0io 204pf+0w
'streams2': 0.200u 0.110s 0:00.31 100.0% 0+0k 0+0io 202pf+0w
Regtested x86-linux.
Paolo.
//////////////
2004-04-25 Paolo Carlini <pcarlini@suse.de>
PR libstdc++/15002 (continued again)
* include/bits/istream.tcc (getline(basic_istream<>&,
basic_string<>&, _CharT)): Use a temporary buffer, thus
avoiding reallocation for common case.
* include/bits/basic_string.tcc (_S_construct(_InIterator,
_InIterator, const _Alloc&, input_iterator_tag)): Tweak size
of temporary buffer to a power of two.
* testsuite/27_io/basic_istream/getline/char/4.cc: Add comment.
diff -prN libstdc++-v3-orig/include/bits/basic_string.tcc libstdc++-v3/include/bits/basic_string.tcc
*** libstdc++-v3-orig/include/bits/basic_string.tcc Tue Apr 20 19:15:22 2004
--- libstdc++-v3/include/bits/basic_string.tcc Sun Apr 25 16:43:59 2004
*************** namespace std
*** 91,97 ****
if (__beg == __end && __a == _Alloc())
return _S_empty_rep()._M_refdata();
// Avoid reallocation for common case.
! _CharT __buf[100];
size_type __len = 0;
while (__beg != __end && __len < sizeof(__buf) / sizeof(_CharT))
{
--- 91,97 ----
if (__beg == __end && __a == _Alloc())
return _S_empty_rep()._M_refdata();
// Avoid reallocation for common case.
! _CharT __buf[128];
size_type __len = 0;
while (__beg != __end && __len < sizeof(__buf) / sizeof(_CharT))
{
diff -prN libstdc++-v3-orig/include/bits/istream.tcc libstdc++-v3/include/bits/istream.tcc
*** libstdc++-v3-orig/include/bits/istream.tcc Fri Apr 23 12:17:58 2004
--- libstdc++-v3/include/bits/istream.tcc Sun Apr 25 17:20:17 2004
*************** namespace std
*** 1102,1108 ****
--- 1102,1111 ----
{
try
{
+ // Avoid reallocation for common case.
__str.erase();
+ _CharT __buf[128];
+ __size_type __len = 0;
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 (__len == sizeof(__buf) / sizeof(_CharT))
! {
! __str.append(__buf, sizeof(__buf) / sizeof(_CharT));
! __len = 0;
! }
! __buf[__len++] = _Traits::to_char_type(__c);
++__extracted;
+ __c = __sb->snextc();
}
+ __str.append(__buf, __len);
+
if (_Traits::eq_int_type(__c, __eof))
__err |= ios_base::eofbit;
else if (_Traits::eq_int_type(__c, __idelim))
diff -prN libstdc++-v3-orig/testsuite/27_io/basic_istream/getline/char/4.cc libstdc++-v3/testsuite/27_io/basic_istream/getline/char/4.cc
*** libstdc++-v3-orig/testsuite/27_io/basic_istream/getline/char/4.cc Sun Apr 25 16:57:58 2004
--- libstdc++-v3/testsuite/27_io/basic_istream/getline/char/4.cc Sun Apr 25 13:48:30 2004
***************
*** 25,30 ****
--- 25,32 ----
// invalidate any other reasons why the executable file might be covered by
// the GNU General Public License.
+ // 27.6.1.3 unformatted input functions
+
#include <cstring> // for strlen
#include <istream>
#include <testsuite_hooks.h>