summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-08-19 18:40:58 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-08-19 18:40:58 +0000
commite813cbaa21c4f090f8b79a611f49480011f25298 (patch)
treeedc9d74a8a3806f1a9db4ddba397d2e74263b41e /llvm/lib/Support
parent45e5670ede6ec952c4eb2051b377d0a039c43970 (diff)
downloadbcm5719-llvm-e813cbaa21c4f090f8b79a611f49480011f25298.tar.gz
bcm5719-llvm-e813cbaa21c4f090f8b79a611f49480011f25298.zip
Change raw_svector_ostream to reserve the input buffer if necessary, Ted was
right. - This class turns out to be much more convenient to use if we do this; clients can make sure the buffer is always big enough if they care (since our current idiom tends to be to use a SmallString<256> for the input to this we should generally be avoiding an unnecessary malloc). Also, add a convenience raw_svector_ostream::str method which flushes the buffer and returns a StringRef for the vector contents. llvm-svn: 79446
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r--llvm/lib/Support/raw_ostream.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index 30bc76b7fd1..917e6be6699 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -487,12 +487,11 @@ void raw_string_ostream::write_impl(const char *Ptr, size_t Size) {
// and we only need to set the vector size when the data is flushed.
raw_svector_ostream::raw_svector_ostream(SmallVectorImpl<char> &O) : OS(O) {
- // Set up the initial external buffer. We enforce that the buffer must have at
+ // Set up the initial external buffer. We make sure that the buffer has at
// least 128 bytes free; raw_ostream itself only requires 64, but we want to
// make sure that we don't grow the buffer unnecessarily on destruction (when
// the data is flushed). See the FIXME below.
- if (OS.capacity() - OS.size() < 128)
- llvm_report_error("Invalid argument, must have at least 128 bytes free!");
+ OS.reserve(OS.size() + 128);
SetBuffer(OS.end(), OS.capacity() - OS.size());
}
@@ -519,6 +518,11 @@ void raw_svector_ostream::write_impl(const char *Ptr, size_t Size) {
uint64_t raw_svector_ostream::current_pos() { return OS.size(); }
+StringRef raw_svector_ostream::str() {
+ flush();
+ return StringRef(OS.begin(), OS.size());
+}
+
//===----------------------------------------------------------------------===//
// raw_null_ostream
//===----------------------------------------------------------------------===//
OpenPOWER on IntegriCloud