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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76910 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Greene 2009-07-23 23:21:10 +00:00
parent eee839dd3c
commit ed0e2adc70
2 changed files with 21 additions and 4 deletions

View File

@ -27,16 +27,23 @@ namespace llvm
/// DELETE_STREAM - Tell the destructor to delete the held stream. /// DELETE_STREAM - Tell the destructor to delete the held stream.
/// ///
const static bool DELETE_STREAM = true; const static bool DELETE_STREAM = true;
/// PRESERVE_STREAM - Tell the destructor to not delete the held /// PRESERVE_STREAM - Tell the destructor to not delete the held
/// stream. /// stream.
/// ///
const static bool PRESERVE_STREAM = false; 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: private:
/// TheStream - The real stream we output to. We set it to be /// TheStream - The real stream we output to. We set it to be
/// unbuffered, since we're already doing our own buffering. /// unbuffered, since we're already doing our own buffering.
/// ///
raw_ostream *TheStream; raw_ostream *TheStream;
/// DeleteStream - Do we need to delete TheStream in the /// DeleteStream - Do we need to delete TheStream in the
/// destructor? /// destructor?
/// ///

View File

@ -12,6 +12,8 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Support/FormattedStream.h" #include "llvm/Support/FormattedStream.h"
#include <algorithm>
using namespace llvm; using namespace llvm;
/// ComputeColumn - Examine the current output and figure out which /// 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) if (NewCol < Column || num < MinPad)
num = MinPad; num = MinPad;
// TODO: Write a whole string at a time. // Keep a buffer of spaces handy to speed up processing.
while (num-- > 0) static char Spaces[MAX_COLUMN_PAD];
write(' '); 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 /// fouts() - This returns a reference to a formatted_raw_ostream for