diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-03-17 01:13:35 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-03-17 01:13:35 +0000 |
commit | 2d603dae2cd8cff21514921dc228279091be404b (patch) | |
tree | 069f40eb47e23e44c069a30fa5695f935b2a393f /llvm/lib/Support/raw_ostream.cpp | |
parent | 87077356be0090df8c647d49d3f58788f91418a6 (diff) | |
download | bcm5719-llvm-2d603dae2cd8cff21514921dc228279091be404b.tar.gz bcm5719-llvm-2d603dae2cd8cff21514921dc228279091be404b.zip |
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.
llvm-svn: 67066
Diffstat (limited to 'llvm/lib/Support/raw_ostream.cpp')
-rw-r--r-- | llvm/lib/Support/raw_ostream.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp index 3b33ad67b14..6aec9478fa2 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -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; } |