[llvm-commits] [llvm] r127026 - /llvm/trunk/lib/Support/raw_ostream.cpp

Benjamin Kramer benny.kra at googlemail.com
Fri Mar 4 11:49:30 PST 2011


Author: d0k
Date: Fri Mar  4 13:49:30 2011
New Revision: 127026

URL: http://llvm.org/viewvc/llvm-project?rev=127026&view=rev
Log:
raw_ostream: while it is generally desirable to do larger writes, it can lead to
inefficient file system buffering if the writes are not a multiple of the desired
buffer size. Avoid this by limiting the large write to a multiple of the buffer
size and copying the remainder into the buffer.

Thanks to Dan for pointing this out.

Modified:
    llvm/trunk/lib/Support/raw_ostream.cpp

Modified: llvm/trunk/lib/Support/raw_ostream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=127026&r1=127025&r2=127026&view=diff
==============================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp (original)
+++ llvm/trunk/lib/Support/raw_ostream.cpp Fri Mar  4 13:49:30 2011
@@ -265,16 +265,20 @@
       return write(Ptr, Size);
     }
 
+    size_t NumBytes = OutBufEnd - OutBufCur;
+
     // If the buffer is empty at this point we have a string that is larger
-    // than the buffer. It's better to write it unbuffered in this case.
+    // than the buffer. Directly write the chunk that is a multiple of the
+    // preferred buffer size and put the remainder in the buffer.
     if (BUILTIN_EXPECT(OutBufCur == OutBufStart, false)) {
-      write_impl(Ptr, Size);
+      size_t BytesToWrite = Size - (Size % NumBytes);
+      write_impl(Ptr, BytesToWrite);
+      copy_to_buffer(Ptr + BytesToWrite, Size - BytesToWrite);
       return *this;
     }
 
     // We don't have enough space in the buffer to fit the string in. Insert as
     // much as possible, flush and start over with the remainder.
-    size_t NumBytes = OutBufEnd - OutBufCur;
     copy_to_buffer(Ptr, NumBytes);
     flush_nonempty();
     return write(Ptr + NumBytes, Size - NumBytes);





More information about the llvm-commits mailing list