summaryrefslogtreecommitdiff
path: root/lib/Support/raw_ostream.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2010-02-15 02:18:26 +0000
committerChris Lattner <sabre@nondot.org>2010-02-15 02:18:26 +0000
commit17f26b4fd2473eb6224527105c293a73193e62e3 (patch)
tree2431a566a9051b392f3de9d3573ab26d8bde7f34 /lib/Support/raw_ostream.cpp
parentefbdaa6463c8febe9cbfdd6d39f3a9ba18773427 (diff)
downloadllvm-17f26b4fd2473eb6224527105c293a73193e62e3.tar.gz
llvm-17f26b4fd2473eb6224527105c293a73193e62e3.tar.bz2
llvm-17f26b4fd2473eb6224527105c293a73193e62e3.tar.xz
enhance raw_svector_ostream::write_impl to work with unbuffered streams,
which may call write_impl on things that are not the usual buffer. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@96209 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/raw_ostream.cpp')
-rw-r--r--lib/Support/raw_ostream.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index af6dc7cf48..25c3fbdef3 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -574,12 +574,18 @@ void raw_svector_ostream::resync() {
}
void raw_svector_ostream::write_impl(const char *Ptr, size_t Size) {
- assert(Ptr == OS.end() && OS.size() + Size <= OS.capacity() &&
- "Invalid write_impl() call!");
-
- // We don't need to copy the bytes, just commit the bytes to the
- // SmallVector.
- OS.set_size(OS.size() + Size);
+ // If we're writing bytes from the end of the buffer into the smallvector, we
+ // don't need to copy the bytes, just commit the bytes because they are
+ // already in the right place.
+ if (Ptr == OS.end()) {
+ assert(OS.size() + Size <= OS.capacity() && "Invalid write_impl() call!");
+ OS.set_size(OS.size() + Size);
+ } else {
+ assert(GetNumBytesInBuffer() == 0 &&
+ "Should be writing from buffer if some bytes in it");
+ // Otherwise, do copy the bytes.
+ OS.append(Ptr, Ptr+Size);
+ }
// Grow the vector if necessary.
if (OS.capacity() - OS.size() < 64)