[llvm-commits] [llvm] r76910 - in /llvm/trunk: include/llvm/Support/FormattedStream.h lib/Support/FormattedStream.cpp

David Greene greened at obbligato.org
Thu Jul 23 16:21:42 PDT 2009


Author: greened
Date: Thu Jul 23 18:21:10 2009
New Revision: 76910

URL: http://llvm.org/viewvc/llvm-project?rev=76910&view=rev
Log:

Write space padding as one string to speed up comment printing.

Modified:
    llvm/trunk/include/llvm/Support/FormattedStream.h
    llvm/trunk/lib/Support/FormattedStream.cpp

Modified: llvm/trunk/include/llvm/Support/FormattedStream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FormattedStream.h?rev=76910&r1=76909&r2=76910&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/FormattedStream.h (original)
+++ llvm/trunk/include/llvm/Support/FormattedStream.h Thu Jul 23 18:21:10 2009
@@ -27,16 +27,23 @@
     /// DELETE_STREAM - Tell the destructor to delete the held stream.
     ///
     const static bool DELETE_STREAM = true;
+
     /// PRESERVE_STREAM - Tell the destructor to not delete the held
     /// stream.
     ///
     const static bool PRESERVE_STREAM = false;
-    
+
+    /// MAX_COLUMN_PAD - This is the maximum column padding we ever
+    /// expect to see.
+    ///
+    const static unsigned MAX_COLUMN_PAD = 100;
+
   private:
     /// TheStream - The real stream we output to. We set it to be
     /// unbuffered, since we're already doing our own buffering.
     ///
     raw_ostream *TheStream;
+
     /// DeleteStream - Do we need to delete TheStream in the
     /// destructor?
     ///

Modified: llvm/trunk/lib/Support/FormattedStream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/FormattedStream.cpp?rev=76910&r1=76909&r2=76910&view=diff

==============================================================================
--- llvm/trunk/lib/Support/FormattedStream.cpp (original)
+++ llvm/trunk/lib/Support/FormattedStream.cpp Thu Jul 23 18:21:10 2009
@@ -12,6 +12,8 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Support/FormattedStream.h"
+#include <algorithm>
+
 using namespace llvm;
 
 /// ComputeColumn - Examine the current output and figure out which
@@ -44,9 +46,17 @@
   if (NewCol < Column || num < MinPad)
     num = MinPad;
 
-  // TODO: Write a whole string at a time.
-  while (num-- > 0)
-    write(' ');
+  // Keep a buffer of spaces handy to speed up processing.
+  static char Spaces[MAX_COLUMN_PAD];
+  static bool Initialized = false;
+  if (!Initialized) {
+    std::fill_n(Spaces, MAX_COLUMN_PAD, ' '),
+    Initialized = true;
+  }
+
+  assert(num < MAX_COLUMN_PAD && "Unexpectedly large column padding");
+
+  write(Spaces, num);
 }
 
 /// fouts() - This returns a reference to a formatted_raw_ostream for





More information about the llvm-commits mailing list