From 01b9372d03cb033f5e1ab866d94242031c11c358 Mon Sep 17 00:00:00 2001 From: paolo Date: Sun, 25 Apr 2004 15:45:13 +0000 Subject: [PATCH] 2004-04-25 Paolo Carlini 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@81163 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 13 +++++++++++++ libstdc++-v3/include/bits/basic_string.tcc | 2 +- libstdc++-v3/include/bits/istream.tcc | 14 ++++++++++++-- .../testsuite/27_io/basic_istream/getline/char/4.cc | 2 ++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0b728ee..df302fa 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,18 @@ 2004-04-25 Paolo Carlini + 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. + +2004-04-25 Paolo Carlini + * testsuite/21_strings/basic_string/inserters_extractors/char/10.cc: New. * testsuite/21_strings/basic_string/inserters_extractors/wchar_t/10.cc: diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc index 8f60abe..7034778 100644 --- a/libstdc++-v3/include/bits/basic_string.tcc +++ b/libstdc++-v3/include/bits/basic_string.tcc @@ -91,7 +91,7 @@ namespace std if (__beg == __end && __a == _Alloc()) return _S_empty_rep()._M_refdata(); // Avoid reallocation for common case. - _CharT __buf[100]; + _CharT __buf[128]; size_type __len = 0; while (__beg != __end && __len < sizeof(__buf) / sizeof(_CharT)) { diff --git a/libstdc++-v3/include/bits/istream.tcc b/libstdc++-v3/include/bits/istream.tcc index a7cf61e..ddd0c03 100644 --- a/libstdc++-v3/include/bits/istream.tcc +++ b/libstdc++-v3/include/bits/istream.tcc @@ -1102,7 +1102,10 @@ namespace std { 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(); @@ -1112,10 +1115,17 @@ namespace std && !_Traits::eq_int_type(__c, __eof) && !_Traits::eq_int_type(__c, __idelim)) { - __str += _Traits::to_char_type(__c); - __c = __sb->snextc(); + 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 --git a/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/4.cc b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/4.cc index 0c53187..2734c60 100644 --- a/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/4.cc +++ b/libstdc++-v3/testsuite/27_io/basic_istream/getline/char/4.cc @@ -25,6 +25,8 @@ // 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 // for strlen #include #include -- 2.7.4