mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-28 19:31:58 +00:00
Re-apply previous changes and improve column padding performance some more.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77461 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
0a28d18cd4
commit
eb85728970
@ -49,14 +49,21 @@ namespace llvm
|
|||||||
///
|
///
|
||||||
bool DeleteStream;
|
bool DeleteStream;
|
||||||
|
|
||||||
/// Column - The current output column of the stream. The column
|
/// ColumnScanned - The current output column of the data that's
|
||||||
/// scheme is zero-based.
|
/// been flushed and the portion of the buffer that's been
|
||||||
|
/// scanned. The column scheme is zero-based.
|
||||||
///
|
///
|
||||||
unsigned Column;
|
unsigned ColumnScanned;
|
||||||
|
|
||||||
|
/// Scanned - This points to one past the last character in the
|
||||||
|
/// buffer we've scanned.
|
||||||
|
///
|
||||||
|
iterator Scanned;
|
||||||
|
|
||||||
virtual void write_impl(const char *Ptr, size_t Size) {
|
virtual void write_impl(const char *Ptr, size_t Size) {
|
||||||
ComputeColumn(Ptr, Size);
|
ComputeColumn();
|
||||||
TheStream->write(Ptr, Size);
|
TheStream->write(Ptr, Size);
|
||||||
|
Scanned = begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// current_pos - Return the current position within the stream,
|
/// current_pos - Return the current position within the stream,
|
||||||
@ -70,7 +77,7 @@ namespace llvm
|
|||||||
/// ComputeColumn - Examine the current output and figure out
|
/// ComputeColumn - Examine the current output and figure out
|
||||||
/// which column we end up in after output.
|
/// which column we end up in after output.
|
||||||
///
|
///
|
||||||
void ComputeColumn(const char *Ptr, size_t Size);
|
void ComputeColumn();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// formatted_raw_ostream - Open the specified file for
|
/// formatted_raw_ostream - Open the specified file for
|
||||||
@ -84,13 +91,16 @@ namespace llvm
|
|||||||
/// underneath it.
|
/// underneath it.
|
||||||
///
|
///
|
||||||
formatted_raw_ostream(raw_ostream &Stream, bool Delete = false)
|
formatted_raw_ostream(raw_ostream &Stream, bool Delete = false)
|
||||||
: raw_ostream(), TheStream(0), DeleteStream(false), Column(0) {
|
: raw_ostream(), TheStream(0), DeleteStream(false), ColumnScanned(0) {
|
||||||
setStream(Stream, Delete);
|
setStream(Stream, Delete);
|
||||||
}
|
}
|
||||||
explicit formatted_raw_ostream()
|
explicit formatted_raw_ostream()
|
||||||
: raw_ostream(), TheStream(0), DeleteStream(false), Column(0) {}
|
: raw_ostream(), TheStream(0), DeleteStream(false), ColumnScanned(0) {
|
||||||
|
Scanned = begin();
|
||||||
|
}
|
||||||
|
|
||||||
~formatted_raw_ostream() {
|
~formatted_raw_ostream() {
|
||||||
|
flush();
|
||||||
if (DeleteStream)
|
if (DeleteStream)
|
||||||
delete TheStream;
|
delete TheStream;
|
||||||
}
|
}
|
||||||
@ -110,6 +120,8 @@ namespace llvm
|
|||||||
if (size_t BufferSize = TheStream->GetNumBytesInBuffer())
|
if (size_t BufferSize = TheStream->GetNumBytesInBuffer())
|
||||||
SetBufferSize(BufferSize);
|
SetBufferSize(BufferSize);
|
||||||
TheStream->SetUnbuffered();
|
TheStream->SetUnbuffered();
|
||||||
|
|
||||||
|
Scanned = begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// PadToColumn - Align the output to some column number.
|
/// PadToColumn - Align the output to some column number.
|
||||||
|
@ -19,16 +19,23 @@ using namespace llvm;
|
|||||||
/// ComputeColumn - Examine the current output and figure out which
|
/// ComputeColumn - Examine the current output and figure out which
|
||||||
/// column we end up in after output.
|
/// column we end up in after output.
|
||||||
///
|
///
|
||||||
void formatted_raw_ostream::ComputeColumn(const char *Ptr, size_t Size) {
|
void formatted_raw_ostream::ComputeColumn() {
|
||||||
// Keep track of the current column by scanning the string for
|
// Keep track of the current column by scanning the string for
|
||||||
// special characters
|
// special characters
|
||||||
|
|
||||||
for (const char *epos = Ptr + Size; Ptr != epos; ++Ptr) {
|
// The buffer may have been allocated underneath us.
|
||||||
++Column;
|
if (Scanned == 0 && GetNumBytesInBuffer() != 0) {
|
||||||
if (*Ptr == '\n' || *Ptr == '\r')
|
Scanned = begin();
|
||||||
Column = 0;
|
}
|
||||||
else if (*Ptr == '\t')
|
|
||||||
Column += (8 - (Column & 0x7)) & 0x7;
|
while (Scanned != end()) {
|
||||||
|
++ColumnScanned;
|
||||||
|
if (*Scanned == '\n' || *Scanned == '\r')
|
||||||
|
ColumnScanned = 0;
|
||||||
|
else if (*Scanned == '\t')
|
||||||
|
// Assumes tab stop = 8 characters.
|
||||||
|
ColumnScanned += (8 - (ColumnScanned & 0x7)) & 0x7;
|
||||||
|
++Scanned;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,21 +45,18 @@ void formatted_raw_ostream::ComputeColumn(const char *Ptr, size_t Size) {
|
|||||||
/// \param MinPad - The minimum space to give after the most recent
|
/// \param MinPad - The minimum space to give after the most recent
|
||||||
/// I/O, even if the current column + minpad > newcol.
|
/// I/O, even if the current column + minpad > newcol.
|
||||||
///
|
///
|
||||||
void formatted_raw_ostream::PadToColumn(unsigned NewCol, unsigned MinPad) {
|
void formatted_raw_ostream::PadToColumn(unsigned NewCol, unsigned MinPad) {
|
||||||
flush();
|
// Figure out what's in the buffer and add it to the column count.
|
||||||
|
ComputeColumn();
|
||||||
|
|
||||||
// Output spaces until we reach the desired column.
|
// Output spaces until we reach the desired column.
|
||||||
unsigned num = NewCol - Column;
|
unsigned num = NewCol - ColumnScanned;
|
||||||
if (NewCol < Column || num < MinPad)
|
if (NewCol < ColumnScanned || num < MinPad)
|
||||||
num = MinPad;
|
num = MinPad;
|
||||||
|
|
||||||
// Keep a buffer of spaces handy to speed up processing.
|
// Keep a buffer of spaces handy to speed up processing.
|
||||||
static char Spaces[MAX_COLUMN_PAD];
|
const char *Spaces = " "
|
||||||
static bool Initialized = false;
|
" ";
|
||||||
if (!Initialized) {
|
|
||||||
std::fill_n(Spaces, MAX_COLUMN_PAD, ' '),
|
|
||||||
Initialized = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(num < MAX_COLUMN_PAD && "Unexpectedly large column padding");
|
assert(num < MAX_COLUMN_PAD && "Unexpectedly large column padding");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user