[llvm-commits] [llvm] r94222 - in /llvm/trunk: include/llvm/Support/raw_ostream.h lib/MC/MCAsmStreamer.cpp lib/Support/raw_ostream.cpp

Chris Lattner sabre at nondot.org
Fri Jan 22 13:16:10 PST 2010


Author: lattner
Date: Fri Jan 22 15:16:10 2010
New Revision: 94222

URL: http://llvm.org/viewvc/llvm-project?rev=94222&view=rev
Log:
Changes to fix buffering that I forgot to commit with previous patch.

Modified:
    llvm/trunk/include/llvm/Support/raw_ostream.h
    llvm/trunk/lib/MC/MCAsmStreamer.cpp
    llvm/trunk/lib/Support/raw_ostream.cpp

Modified: llvm/trunk/include/llvm/Support/raw_ostream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/raw_ostream.h?rev=94222&r1=94221&r2=94222&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/raw_ostream.h (original)
+++ llvm/trunk/include/llvm/Support/raw_ostream.h Fri Jan 22 15:16:10 2010
@@ -456,8 +456,10 @@
   explicit raw_svector_ostream(SmallVectorImpl<char> &O);
   ~raw_svector_ostream();
 
-  /// clear - Flush the stream and clear the underlying vector.
-  void clear();
+  /// resync - This is called when the SmallVector we're appending to is changed
+  /// outside of the raw_svector_ostream's control.  It is only safe to do this
+  /// if the raw_svector_ostream has previously been flushed.
+  void resync();
   
   /// str - Flushes the stream contents to the target vector and return a
   /// StringRef for the vector contents.

Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=94222&r1=94221&r2=94222&view=diff

==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Fri Jan 22 15:16:10 2010
@@ -136,6 +136,9 @@
   T.toVector(CommentToEmit);
   // Each comment goes on its own line.
   CommentToEmit.push_back('\n');
+  
+  // Tell the comment stream that the vector changed underneath it.
+  CommentStream.resync();
 }
 
 void MCAsmStreamer::EmitCommentsAndEOL() {
@@ -158,7 +161,9 @@
     Comments = Comments.substr(Position+1);
   } while (!Comments.empty());
   
-  CommentStream.clear();
+  CommentToEmit.clear();
+  // Tell the comment stream that the vector changed underneath it.
+  CommentStream.resync();
 }
 
 

Modified: llvm/trunk/lib/Support/raw_ostream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=94222&r1=94221&r2=94222&view=diff

==============================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp (original)
+++ llvm/trunk/lib/Support/raw_ostream.cpp Fri Jan 22 15:16:10 2010
@@ -562,11 +562,14 @@
   flush();
 }
 
-/// clear - Flush the stream and clear the underlying vector.
-void raw_svector_ostream::clear() {
-  if (GetNumBytesInBuffer() == 0) flush();
-  
-  OS.clear();
+/// resync - This is called when the SmallVector we're appending to is changed
+/// outside of the raw_svector_ostream's control.  It is only safe to do this
+/// if the raw_svector_ostream has previously been flushed.
+void raw_svector_ostream::resync() {
+  assert(GetNumBytesInBuffer() == 0 && "Didn't flush before mutating vector");
+
+  if (OS.capacity() - OS.size() < 64)
+    OS.reserve(OS.capacity() * 2);
   SetBuffer(OS.end(), OS.capacity() - OS.size());
 }
 





More information about the llvm-commits mailing list