summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/raw_ostream.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-03-17 01:36:56 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-03-17 01:36:56 +0000
commit64fa3860ed35ddb3d811c9512b6d41c6c00c13e5 (patch)
tree2b4cfb434b932e3c9cbb6bde900689e18926b340 /llvm/lib/Support/raw_ostream.cpp
parent76f1b47ec9ff0c91a48b86329d77596d81717546 (diff)
downloadbcm5719-llvm-64fa3860ed35ddb3d811c9512b6d41c6c00c13e5.tar.gz
bcm5719-llvm-64fa3860ed35ddb3d811c9512b6d41c6c00c13e5.zip
raw_ostream: Put all exceptional conditions in raw_ostream::write
under a single branch. Also, add a FIXME for formatted output. llvm-svn: 67069
Diffstat (limited to 'llvm/lib/Support/raw_ostream.cpp')
-rw-r--r--llvm/lib/Support/raw_ostream.cpp48
1 files changed, 30 insertions, 18 deletions
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index 6aec9478fa2..639d6fa570f 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -123,30 +123,36 @@ void raw_ostream::flush_nonempty() {
}
raw_ostream &raw_ostream::write(unsigned char C) {
- if (Unbuffered) {
- write_impl(reinterpret_cast<char*>(&C), 1);
- return *this;
+ // Group exceptional cases into a single branch.
+ if (OutBufCur >= OutBufEnd) {
+ if (Unbuffered) {
+ write_impl(reinterpret_cast<char*>(&C), 1);
+ return *this;
+ }
+
+ if (!OutBufStart)
+ SetBufferSize();
+ else
+ flush_nonempty();
}
- if (!OutBufStart)
- SetBufferSize();
- else if (OutBufCur >= OutBufEnd)
- flush_nonempty();
-
*OutBufCur++ = C;
return *this;
}
raw_ostream &raw_ostream::write(const char *Ptr, unsigned Size) {
- if (Unbuffered) {
- write_impl(Ptr, Size);
- return *this;
- }
+ // Group exceptional cases into a single branch.
+ if (OutBufCur+Size > OutBufEnd) {
+ if (Unbuffered) {
+ write_impl(Ptr, Size);
+ return *this;
+ }
- if (!OutBufStart)
- SetBufferSize();
- else if (OutBufCur+Size > OutBufEnd)
- flush_nonempty();
+ if (!OutBufStart)
+ SetBufferSize();
+ else
+ flush_nonempty();
+ }
// Handle short strings specially, memcpy isn't very good at very short
// strings.
@@ -176,8 +182,14 @@ raw_ostream &raw_ostream::write(const char *Ptr, unsigned Size) {
// Formatted output.
raw_ostream &raw_ostream::operator<<(const format_object_base &Fmt) {
- // If we have more than a few bytes left in our output buffer, try formatting
- // directly onto its end.
+ // If we have more than a few bytes left in our output buffer, try
+ // formatting directly onto its end.
+ //
+ // FIXME: This test is a bit silly, since if we don't have enough
+ // space in the buffer we will have to flush the formatted output
+ // anyway. We should just flush upfront in such cases, and use the
+ // whole buffer as our scratch pad. Note, however, that this case is
+ // also necessary for correctness on unbuffered streams.
unsigned NextBufferSize = 127;
if (OutBufEnd-OutBufCur > 3) {
unsigned BufferBytesLeft = OutBufEnd-OutBufCur;
OpenPOWER on IntegriCloud