aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Support
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-03-16 23:29:31 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-03-16 23:29:31 +0000
commit89a66a96fed75796bc5e079217130b62105cb438 (patch)
tree74be4a1cb79a17d4079f9a1cde3cecbe3750f22e /lib/Support
parentcf2a2c6a26427733f31dd539c6ee6486ea191da2 (diff)
downloadexternal_llvm-89a66a96fed75796bc5e079217130b62105cb438.zip
external_llvm-89a66a96fed75796bc5e079217130b62105cb438.tar.gz
external_llvm-89a66a96fed75796bc5e079217130b62105cb438.tar.bz2
raw_ostream: Replace flush_impl with write_impl, which takes data to
write as arguments. - Add raw_ostream::GetNumBytesInBuffer. - Privatize buffer pointers. - Get rid of slow and unnecessary code for writing out large strings. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@67060 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/raw_ostream.cpp47
1 files changed, 15 insertions, 32 deletions
diff --git a/lib/Support/raw_ostream.cpp b/lib/Support/raw_ostream.cpp
index bbd1994..3b33ad6 100644
--- a/lib/Support/raw_ostream.cpp
+++ b/lib/Support/raw_ostream.cpp
@@ -118,7 +118,7 @@ raw_ostream &raw_ostream::operator<<(const void *P) {
void raw_ostream::flush_nonempty() {
assert(OutBufCur > OutBufStart && "Invalid call to flush_nonempty.");
- flush_impl();
+ write_impl(OutBufStart, OutBufCur - OutBufStart);
OutBufCur = OutBufStart;
}
@@ -151,20 +151,12 @@ raw_ostream &raw_ostream::write(const char *Ptr, unsigned Size) {
if (Size <= unsigned(OutBufEnd-OutBufStart)) {
memcpy(OutBufCur, Ptr, Size);
break;
- }
+ }
- // If emitting a string larger than our buffer, emit in chunks. In this
- // case we know that we just flushed the buffer.
- while (Size) {
- unsigned NumToEmit = OutBufEnd-OutBufStart;
- if (Size < NumToEmit) NumToEmit = Size;
- assert(OutBufCur == OutBufStart);
- memcpy(OutBufStart, Ptr, NumToEmit);
- Ptr += NumToEmit;
- Size -= NumToEmit;
- OutBufCur = OutBufStart + NumToEmit;
- flush_nonempty();
- }
+ // Otherwise we are emitting a string larger than our buffer. We
+ // know we already flushed, so just write it out directly.
+ write_impl(Ptr, Size);
+ Size = 0;
break;
}
OutBufCur += Size;
@@ -268,10 +260,10 @@ raw_fd_ostream::~raw_fd_ostream() {
}
}
-void raw_fd_ostream::flush_impl() {
+void raw_fd_ostream::write_impl(const char *Ptr, unsigned Size) {
assert (FD >= 0 && "File already closed.");
- pos += (OutBufCur - OutBufStart);
- ::write(FD, OutBufStart, OutBufCur-OutBufStart);
+ pos += Size;
+ ::write(FD, Ptr, Size);
}
void raw_fd_ostream::close() {
@@ -322,11 +314,8 @@ raw_os_ostream::~raw_os_ostream() {
flush();
}
-/// flush_impl - The is the piece of the class that is implemented by
-/// subclasses. This outputs the currently buffered data and resets the
-/// buffer to empty.
-void raw_os_ostream::flush_impl() {
- OS.write(OutBufStart, OutBufCur-OutBufStart);
+void raw_os_ostream::write_impl(const char *Ptr, unsigned Size) {
+ OS.write(Ptr, Size);
}
//===----------------------------------------------------------------------===//
@@ -337,11 +326,8 @@ raw_string_ostream::~raw_string_ostream() {
flush();
}
-/// flush_impl - The is the piece of the class that is implemented by
-/// subclasses. This outputs the currently buffered data and resets the
-/// buffer to empty.
-void raw_string_ostream::flush_impl() {
- OS.append(OutBufStart, OutBufCur-OutBufStart);
+void raw_string_ostream::write_impl(const char *Ptr, unsigned Size) {
+ OS.append(Ptr, Size);
}
//===----------------------------------------------------------------------===//
@@ -352,10 +338,7 @@ raw_svector_ostream::~raw_svector_ostream() {
flush();
}
-/// flush_impl - The is the piece of the class that is implemented by
-/// subclasses. This outputs the currently buffered data and resets the
-/// buffer to empty.
-void raw_svector_ostream::flush_impl() {
- OS.append(OutBufStart, OutBufCur);
+void raw_svector_ostream::write_impl(const char *Ptr, unsigned Size) {
+ OS.append(Ptr, Ptr + Size);
}