aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-07-16 15:37:26 +0000
committerDan Gohman <gohman@apple.com>2009-07-16 15:37:26 +0000
commit4d2b7f46703dbe517a6cd931ed047533ff0af3cd (patch)
treeb62eac1c14e61e221bd9eb8252dfd780ce17d67d
parentea87f79e9bc085b97790d850a74cf675c7c18fc5 (diff)
downloadexternal_llvm-4d2b7f46703dbe517a6cd931ed047533ff0af3cd.zip
external_llvm-4d2b7f46703dbe517a6cd931ed047533ff0af3cd.tar.gz
external_llvm-4d2b7f46703dbe517a6cd931ed047533ff0af3cd.tar.bz2
Use setStream infomatted_raw_ostream's constructor, to reduce code
duplication. Also, make setStream honor the old DeleteStream flag. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76075 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Support/FormattedStream.h19
1 files changed, 9 insertions, 10 deletions
diff --git a/include/llvm/Support/FormattedStream.h b/include/llvm/Support/FormattedStream.h
index bd330dc..dc30cdb 100644
--- a/include/llvm/Support/FormattedStream.h
+++ b/include/llvm/Support/FormattedStream.h
@@ -77,15 +77,8 @@ namespace llvm
/// underneath it.
///
formatted_raw_ostream(raw_ostream &Stream, bool Delete = false)
- : raw_ostream(), TheStream(&Stream), DeleteStream(Delete), Column(0) {
- // This formatted_raw_ostream inherits from raw_ostream, so it'll do its
- // own buffering, and it doesn't need or want TheStream to do another
- // layer of buffering underneath. Resize the buffer to what TheStream
- // had been using, and tell TheStream not to do its own buffering.
- TheStream->flush();
- if (size_t BufferSize = TheStream->GetNumBytesInBuffer())
- SetBufferSize(BufferSize);
- TheStream->SetUnbuffered();
+ : raw_ostream(), TheStream(0), DeleteStream(false), Column(0) {
+ setStream(Stream, Delete);
}
explicit formatted_raw_ostream()
: raw_ostream(), TheStream(0), DeleteStream(false), Column(0) {}
@@ -96,10 +89,16 @@ namespace llvm
}
void setStream(raw_ostream &Stream, bool Delete = false) {
+ if (DeleteStream)
+ delete TheStream;
+
TheStream = &Stream;
DeleteStream = Delete;
- // Avoid double-buffering, as above.
+ // This formatted_raw_ostream inherits from raw_ostream, so it'll do its
+ // own buffering, and it doesn't need or want TheStream to do another
+ // layer of buffering underneath. Resize the buffer to what TheStream
+ // had been using, and tell TheStream not to do its own buffering.
TheStream->flush();
if (size_t BufferSize = TheStream->GetNumBytesInBuffer())
SetBufferSize(BufferSize);