summaryrefslogtreecommitdiffstats
path: root/llvm/lib
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
commit115158fa4f209a3d14b7a7e4017b2d22f48549d6 (patch)
treeb17d8e1fc8aed60e8e1aed1d8717243affd26fb1 /llvm/lib
parentf733d75892698d14225f9bff701c4808cfc5dcc1 (diff)
downloadbcm5719-llvm-115158fa4f209a3d14b7a7e4017b2d22f48549d6.tar.gz
bcm5719-llvm-115158fa4f209a3d14b7a7e4017b2d22f48549d6.zip
enhance raw_svector_ostream::write_impl to work with unbuffered streams,
which may call write_impl on things that are not the usual buffer. llvm-svn: 96209
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Support/raw_ostream.cpp18
1 files changed, 12 insertions, 6 deletions
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index af6dc7cf48b..25c3fbdef32 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/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)
OpenPOWER on IntegriCloud