raw_ostream: Rework implementation of unbuffered streams so outputting

a single character requires only one branch to follow slow path.
 - Never use a buffer when writing on an unbuffered stream.

 - Move default buffer size to header.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67066 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Daniel Dunbar
2009-03-17 01:13:35 +00:00
parent 6b23339502
commit d17d74bb80
2 changed files with 30 additions and 19 deletions

View File

@@ -123,8 +123,13 @@ void raw_ostream::flush_nonempty() {
}
raw_ostream &raw_ostream::write(unsigned char C) {
if (Unbuffered) {
write_impl(reinterpret_cast<char*>(&C), 1);
return *this;
}
if (!OutBufStart)
SetBufferSize(4096);
SetBufferSize();
else if (OutBufCur >= OutBufEnd)
flush_nonempty();
@@ -133,8 +138,13 @@ raw_ostream &raw_ostream::write(unsigned char C) {
}
raw_ostream &raw_ostream::write(const char *Ptr, unsigned Size) {
if (Unbuffered) {
write_impl(Ptr, Size);
return *this;
}
if (!OutBufStart)
SetBufferSize(4096);
SetBufferSize();
else if (OutBufCur+Size > OutBufEnd)
flush_nonempty();
@@ -161,8 +171,6 @@ raw_ostream &raw_ostream::write(const char *Ptr, unsigned Size) {
}
OutBufCur += Size;
if (Unbuffered)
flush();
return *this;
}