[libcxx] r229866 - Make basic_streambuf::xsputn write characters in chunks whenever possible, instead of one at a time. References PR#10193

Marshall Clow mclow.lists at gmail.com
Thu Feb 19 08:17:47 PST 2015


Author: marshall
Date: Thu Feb 19 10:17:46 2015
New Revision: 229866

URL: http://llvm.org/viewvc/llvm-project?rev=229866&view=rev
Log:
Make basic_streambuf::xsputn write characters in chunks whenever possible, instead of one at a time. References PR#10193

Modified:
    libcxx/trunk/include/streambuf

Modified: libcxx/trunk/include/streambuf
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/streambuf?rev=229866&r1=229865&r2=229866&view=diff
==============================================================================
--- libcxx/trunk/include/streambuf (original)
+++ libcxx/trunk/include/streambuf Thu Feb 19 10:17:46 2015
@@ -536,12 +536,23 @@ basic_streambuf<_CharT, _Traits>::xsputn
 {
     streamsize __i = 0;
     int_type __eof = traits_type::eof();
-    for (; __i < __n; ++__s, ++__i)
+    while( __i < __n)
     {
-        if (__nout_ < __eout_)
-            *__nout_++ = *__s;
-        else if (overflow(traits_type::to_int_type(*__s)) == __eof)
-            break;
+        if (__nout_ >= __eout_)
+        {
+            if (overflow(traits_type::to_int_type(*__s)) == __eof)
+                break;
+            ++__s;
+            ++__i;
+        }
+        else
+        {
+            streamsize __chunk_size = _VSTD::min(__eout_ - __nout_, __n - __i);
+            traits_type::copy(__nout_, __s, __chunk_size);
+            __nout_ += __chunk_size;
+            __s     += __chunk_size;
+            __i     += __chunk_size;
+        }
     }
     return __i;
 }





More information about the cfe-commits mailing list