From 8e621f01824f2e2873f11950de35ccc3e4d7cbb1 Mon Sep 17 00:00:00 2001 From: David Greene Date: Thu, 23 Jul 2009 23:21:10 +0000 Subject: [PATCH] Write space padding as one string to speed up comment printing. llvm-svn: 76910 --- llvm/include/llvm/Support/FormattedStream.h | 9 ++++++++- llvm/lib/Support/FormattedStream.cpp | 16 +++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/llvm/include/llvm/Support/FormattedStream.h b/llvm/include/llvm/Support/FormattedStream.h index dc30cdb5..4b13ff2 100644 --- a/llvm/include/llvm/Support/FormattedStream.h +++ b/llvm/include/llvm/Support/FormattedStream.h @@ -27,16 +27,23 @@ namespace llvm /// 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? /// 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 + 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 -- 2.7.4