aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/FormattedStream.cpp
diff options
context:
space:
mode:
authorDavid Greene <greened@obbligato.org>2009-07-23 23:21:10 +0000
committerDavid Greene <greened@obbligato.org>2009-07-23 23:21:10 +0000
commit8e621f01824f2e2873f11950de35ccc3e4d7cbb1 (patch)
tree03dcfd560a17b5daeb5ef30785e22c89715c6b8e /llvm/lib/Support/FormattedStream.cpp
parentdc99f0711393df08e29dadf9caedc428d15ae9df (diff)
downloadllvm-8e621f01824f2e2873f11950de35ccc3e4d7cbb1.zip
llvm-8e621f01824f2e2873f11950de35ccc3e4d7cbb1.tar.gz
llvm-8e621f01824f2e2873f11950de35ccc3e4d7cbb1.tar.bz2
Write space padding as one string to speed up comment printing.
llvm-svn: 76910
Diffstat (limited to 'llvm/lib/Support/FormattedStream.cpp')
-rw-r--r--llvm/lib/Support/FormattedStream.cpp16
1 files changed, 13 insertions, 3 deletions
diff --git a/llvm/lib/Support/FormattedStream.cpp b/llvm/lib/Support/FormattedStream.cpp
index 3523e2d..1796f9f 100644
--- a/llvm/lib/Support/FormattedStream.cpp
+++ b/llvm/lib/Support/FormattedStream.cpp
@@ -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 @@ void formatted_raw_ostream::PadToColumn(unsigned NewCol, unsigned MinPad) {
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