PR libstdc++/15002 (continued again)
authorPaolo Carlini <pcarlini@suse.de>
Sun, 25 Apr 2004 15:45:13 +0000 (15:45 +0000)
committerPaolo Carlini <paolo@gcc.gnu.org>
Sun, 25 Apr 2004 15:45:13 +0000 (15:45 +0000)
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.

From-SVN: r81163

libstdc++-v3/ChangeLog
libstdc++-v3/include/bits/basic_string.tcc
libstdc++-v3/include/bits/istream.tcc
libstdc++-v3/testsuite/27_io/basic_istream/getline/char/4.cc

index 0b728ee3ff62e34b2621c5081db0a852e36d34ed..df302fa9524a811019925f1e36d8d64cfd4dd839 100644 (file)
@@ -1,3 +1,16 @@
+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.
+
 2004-04-25  Paolo Carlini  <pcarlini@suse.de>
 
        * testsuite/21_strings/basic_string/inserters_extractors/char/10.cc:
index 8f60abef52668aff044598553826dcb5a483af24..7034778e9dff1c5db9988cd14bb161ad5696fd00 100644 (file)
@@ -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))
          {
index a7cf61e4353b39b4de704412caf69a443817329f..ddd0c03fbd658c55591a4a28cb8b87827f87ab4c 100644 (file)
@@ -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))
index 0c531873eb93fe52d9e7005d9bf3035b69bb8ddd..2734c60fd2ed108bba53433284b06909ef87f3a5 100644 (file)
@@ -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 <cstring> // for strlen
 #include <istream>
 #include <testsuite_hooks.h>