mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-05-17 15:38:40 +00:00
Improve performance of PadToColumn by eliminating flushes.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77397 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
a87861e4f8
commit
7aaad71722
@ -49,13 +49,13 @@ namespace llvm
|
|||||||
///
|
///
|
||||||
bool DeleteStream;
|
bool DeleteStream;
|
||||||
|
|
||||||
/// Column - The current output column of the stream. The column
|
/// ColumnFlushed - The current output column of the data that's
|
||||||
/// scheme is zero-based.
|
/// been flushed. The column scheme is zero-based.
|
||||||
///
|
///
|
||||||
unsigned Column;
|
unsigned ColumnFlushed;
|
||||||
|
|
||||||
virtual void write_impl(const char *Ptr, size_t Size) {
|
virtual void write_impl(const char *Ptr, size_t Size) {
|
||||||
ComputeColumn(Ptr, Size);
|
ComputeColumn(ColumnFlushed);
|
||||||
TheStream->write(Ptr, Size);
|
TheStream->write(Ptr, Size);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,10 +67,10 @@ namespace llvm
|
|||||||
return TheStream->tell() - TheStream->GetNumBytesInBuffer();
|
return TheStream->tell() - TheStream->GetNumBytesInBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ComputeColumn - Examine the current output and figure out
|
/// ComputeColumn - Examine the current buffer and figure out
|
||||||
/// which column we end up in after output.
|
/// which column we're in.
|
||||||
///
|
///
|
||||||
void ComputeColumn(const char *Ptr, size_t Size);
|
void ComputeColumn(unsigned &Column);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// formatted_raw_ostream - Open the specified file for
|
/// formatted_raw_ostream - Open the specified file for
|
||||||
@ -84,11 +84,11 @@ 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), ColumnFlushed(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), ColumnFlushed(0) {}
|
||||||
|
|
||||||
~formatted_raw_ostream() {
|
~formatted_raw_ostream() {
|
||||||
if (DeleteStream)
|
if (DeleteStream)
|
||||||
|
@ -19,11 +19,11 @@ 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(unsigned &Column) {
|
||||||
// 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) {
|
for (const char *Ptr = begin(); Ptr != end(); ++Ptr) {
|
||||||
++Column;
|
++Column;
|
||||||
if (*Ptr == '\n' || *Ptr == '\r')
|
if (*Ptr == '\n' || *Ptr == '\r')
|
||||||
Column = 0;
|
Column = 0;
|
||||||
@ -38,8 +38,13 @@ 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();
|
// Start out from the last flush position.
|
||||||
|
unsigned Column = ColumnFlushed;
|
||||||
|
|
||||||
|
// Now figure out what's in the buffer and add it to the column
|
||||||
|
// count.
|
||||||
|
ComputeColumn(Column);
|
||||||
|
|
||||||
// Output spaces until we reach the desired column.
|
// Output spaces until we reach the desired column.
|
||||||
unsigned num = NewCol - Column;
|
unsigned num = NewCol - Column;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user