aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support/raw_ostream.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-08-19 00:23:39 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-08-19 00:23:39 +0000
commitecc67e2e1b2c13c99427510fff71d598086eb309 (patch)
treec2c3e2789201f1b4d1657c36b06392b967879365 /lib/Support/raw_ostream.cpp
parentd29d497b530a7094c808540cfdb68a7af3afd315 (diff)
downloadexternal_llvm-ecc67e2e1b2c13c99427510fff71d598086eb309.zip
external_llvm-ecc67e2e1b2c13c99427510fff71d598086eb309.tar.gz
external_llvm-ecc67e2e1b2c13c99427510fff71d598086eb309.tar.bz2
raw_ostream: Simplify write(unsigned char) to match write(const char*, unsigned).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79386 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/raw_ostream.cpp')
-rw-r--r--lib/Support/raw_ostream.cpp26
1 files changed, 8 insertions, 18 deletions
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index 3b678bd..4c3348d 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -185,23 +185,18 @@ void raw_ostream::flush_nonempty() {
raw_ostream &raw_ostream::write(unsigned char C) {
// Group exceptional cases into a single branch.
- if (OutBufCur >= OutBufEnd) {
- if (BufferMode == Unbuffered) {
- write_impl(reinterpret_cast<char*>(&C), 1);
- return *this;
- }
-
- if (OutBufStart)
- flush_nonempty();
- else {
- SetBuffered();
- // It's possible for the underlying stream to decline
- // buffering, so check this condition again.
+ if (BUILTIN_EXPECT(OutBufCur >= OutBufEnd, false)) {
+ if (BUILTIN_EXPECT(!OutBufStart, false)) {
if (BufferMode == Unbuffered) {
write_impl(reinterpret_cast<char*>(&C), 1);
return *this;
}
+ // Set up a buffer and start over.
+ SetBuffered();
+ return write(C);
}
+
+ flush_nonempty();
}
*OutBufCur++ = C;
@@ -220,6 +215,7 @@ raw_ostream &raw_ostream::write(const char *Ptr, size_t Size) {
SetBuffered();
return write(Ptr, Size);
}
+
// Write out the data in buffer-sized blocks until the remainder
// fits within the buffer.
do {
@@ -259,12 +255,6 @@ void raw_ostream::copy_to_buffer(const char *Ptr, size_t Size) {
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.
- //
- // 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.
size_t NextBufferSize = 127;
if (OutBufEnd-OutBufCur > 3) {
size_t BufferBytesLeft = OutBufEnd-OutBufCur;