Drop the raw_ostream required buffer size to 1.
authorDaniel Dunbar <daniel@zuster.org>
Tue, 15 Sep 2009 20:31:46 +0000 (20:31 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Tue, 15 Sep 2009 20:31:46 +0000 (20:31 +0000)
 - As best I can tell, we have eliminated all the code which used to require a
   larger buffer size.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81912 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/raw_ostream.h
lib/Support/raw_ostream.cpp
unittests/Support/raw_ostream_test.cpp

index dbad40ca91c19873cc1b3413977f5c0642c624a9..7827dd83804b512a1e49a9a5dcb5f293c85b2478 100644 (file)
@@ -41,7 +41,7 @@ private:
   ///  1. Unbuffered (BufferMode == Unbuffered)
   ///  1. Uninitialized (BufferMode != Unbuffered && OutBufStart == 0).
   ///  2. Buffered (BufferMode != Unbuffered && OutBufStart != 0 &&
-  ///               OutBufEnd - OutBufStart >= 64).
+  ///               OutBufEnd - OutBufStart >= 1).
   ///
   /// If buffered, then the raw_ostream owns the buffer if (BufferMode ==
   /// InternalBuffer); otherwise the buffer has been set via SetBuffer and is
index 2cb3771287296ee04129746bd70b13563e020468..0a82cc1d10c394ff33fceb2b55bcdc2c26d5f63e 100644 (file)
@@ -84,8 +84,8 @@ void raw_ostream::SetBuffered() {
 void raw_ostream::SetBufferAndMode(char *BufferStart, size_t Size, 
                                     BufferKind Mode) {
   assert(((Mode == Unbuffered && BufferStart == 0 && Size == 0) || 
-          (Mode != Unbuffered && BufferStart && Size >= 64)) &&
-         "stream must be unbuffered, or have >= 64 bytes of buffer");
+          (Mode != Unbuffered && BufferStart && Size)) &&
+         "stream must be unbuffered or have at least one byte");
   // Make sure the current buffer is free of content (we can't flush here; the
   // child buffer management logic will be in write_impl).
   assert(GetNumBytesInBuffer() == 0 && "Current buffer is non-empty!");
index 52639ba7a2f9faa303e559239c260a53874ea9ca..bd2e95cbb531418b7e9fb46fa4fe127497ae9432 100644 (file)
@@ -117,4 +117,14 @@ TEST(raw_ostreamTest, BufferEdge) {
   EXPECT_EQ("1.20", printToString(format("%.2f", 1.2), 10));
 }
 
+TEST(raw_ostreamTest, TinyBuffer) {
+  std::string Str;
+  raw_string_ostream OS(Str);
+  OS.SetBufferSize(1);
+  OS << "hello";
+  OS << 1;
+  OS << 'w' << 'o' << 'r' << 'l' << 'd';
+  EXPECT_EQ("hello1world", OS.str());
+}
+
 }