aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support/raw_ostream.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2011-03-04 19:49:30 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2011-03-04 19:49:30 +0000
commitca9714470ec51ec52833eee46bca0062d92e92f3 (patch)
tree441122779c4c9022280288881e8ab58d46bfee1a /lib/Support/raw_ostream.cpp
parent979869c28e5bc68e2d4d546c7019525177f1d399 (diff)
downloadexternal_llvm-ca9714470ec51ec52833eee46bca0062d92e92f3.zip
external_llvm-ca9714470ec51ec52833eee46bca0062d92e92f3.tar.gz
external_llvm-ca9714470ec51ec52833eee46bca0062d92e92f3.tar.bz2
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127026 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/raw_ostream.cpp')
-rw-r--r--lib/Support/raw_ostream.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index b8839e2..b175d20 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -265,16 +265,20 @@ raw_ostream &raw_ostream::write(const char *Ptr, size_t Size) {
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);