diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 0b728ee3ff6..df302fa9524 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,16 @@ +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: diff --git a/libstdc++-v3/include/bits/basic_string.tcc b/libstdc++-v3/include/bits/basic_string.tcc index 8f60abef526..7034778e9df 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 a7cf61e4353..ddd0c03fbd6 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 0c531873eb9..2734c60fd2e 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