[llvm-commits] [llvm] r79386 - /llvm/trunk/lib/Support/raw_ostream.cpp

Daniel Dunbar daniel at zuster.org
Tue Aug 18 17:23:39 PDT 2009


Author: ddunbar
Date: Tue Aug 18 19:23:39 2009
New Revision: 79386

URL: http://llvm.org/viewvc/llvm-project?rev=79386&view=rev
Log:
raw_ostream: Simplify write(unsigned char) to match write(const char*, unsigned).

Modified:
    llvm/trunk/lib/Support/raw_ostream.cpp

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

==============================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp (original)
+++ llvm/trunk/lib/Support/raw_ostream.cpp Tue Aug 18 19:23:39 2009
@@ -185,23 +185,18 @@
 
 raw_ostream &raw_ostream::write(unsigned char C) {
   // Group exceptional cases into a single branch.
-  if (OutBufCur >= OutBufEnd) {
-    if (BufferMode == Unbuffered) {
-      write_impl(reinterpret_cast<char*>(&C), 1);
-      return *this;
-    }
-    
-    if (OutBufStart)
-      flush_nonempty();
-    else {
-      SetBuffered();
-      // It's possible for the underlying stream to decline
-      // buffering, so check this condition again.
+  if (BUILTIN_EXPECT(OutBufCur >= OutBufEnd, false)) {
+    if (BUILTIN_EXPECT(!OutBufStart, false)) {
       if (BufferMode == Unbuffered) {
         write_impl(reinterpret_cast<char*>(&C), 1);
         return *this;
       }
+      // Set up a buffer and start over.
+      SetBuffered();
+      return write(C);
     }
+
+    flush_nonempty();
   }
 
   *OutBufCur++ = C;
@@ -220,6 +215,7 @@
       SetBuffered();
       return write(Ptr, Size);
     }
+
     // Write out the data in buffer-sized blocks until the remainder
     // fits within the buffer.
     do {
@@ -259,12 +255,6 @@
 raw_ostream &raw_ostream::operator<<(const format_object_base &Fmt) {
   // If we have more than a few bytes left in our output buffer, try
   // formatting directly onto its end.
-  //
-  // FIXME: This test is a bit silly, since if we don't have enough
-  // space in the buffer we will have to flush the formatted output
-  // anyway. We should just flush upfront in such cases, and use the
-  // whole buffer as our scratch pad. Note, however, that this case is
-  // also necessary for correctness on unbuffered streams.
   size_t NextBufferSize = 127;
   if (OutBufEnd-OutBufCur > 3) {
     size_t BufferBytesLeft = OutBufEnd-OutBufCur;





More information about the llvm-commits mailing list