diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2011-03-04 18:18:16 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2011-03-04 18:18:16 +0000 |
commit | acf08420882298c89b1b657e698b5a93b6dcc85c (patch) | |
tree | ac639c5d2482f063e6eada6e53b341e5d0c79369 /llvm/lib/Support/raw_ostream.cpp | |
parent | 3b83d63a179b7249a667eb0d4ce416fec72f1c3b (diff) | |
download | bcm5719-llvm-acf08420882298c89b1b657e698b5a93b6dcc85c.tar.gz bcm5719-llvm-acf08420882298c89b1b657e698b5a93b6dcc85c.zip |
raw_ostream: If writing a string that is larger than the buffer, write it directly instead of doing many buffer-sized writes.
This caps the number of write(2) calls per string to a maximum of 2.
llvm-svn: 127010
Diffstat (limited to 'llvm/lib/Support/raw_ostream.cpp')
-rw-r--r-- | llvm/lib/Support/raw_ostream.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp index 80ea7407b44..b8839e2943b 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -265,15 +265,19 @@ raw_ostream &raw_ostream::write(const char *Ptr, size_t Size) { return write(Ptr, Size); } - // Write out the data in buffer-sized blocks until the remainder - // fits within the buffer. - do { - size_t NumBytes = OutBufEnd - OutBufCur; - copy_to_buffer(Ptr, NumBytes); - flush_nonempty(); - Ptr += NumBytes; - Size -= NumBytes; - } while (OutBufCur+Size > OutBufEnd); + // 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. + if (BUILTIN_EXPECT(OutBufCur == OutBufStart, false)) { + write_impl(Ptr, Size); + 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); } copy_to_buffer(Ptr, Size); |