[llvm-commits] [llvm] r60560 - in /llvm/trunk: include/llvm/Support/raw_ostream.h lib/Support/raw_ostream.cpp

Ted Kremenek kremenek at apple.com
Thu Dec 4 14:51:11 PST 2008


Author: kremenek
Date: Thu Dec  4 16:51:11 2008
New Revision: 60560

URL: http://llvm.org/viewvc/llvm-project?rev=60560&view=rev
Log:
Have raw_fd_ostream keep track of the position in the file to make tell() go faster by not requiring a flush().

Modified:
    llvm/trunk/include/llvm/Support/raw_ostream.h
    llvm/trunk/lib/Support/raw_ostream.cpp

Modified: llvm/trunk/include/llvm/Support/raw_ostream.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/raw_ostream.h?rev=60560&r1=60559&r2=60560&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/raw_ostream.h (original)
+++ llvm/trunk/include/llvm/Support/raw_ostream.h Thu Dec  4 16:51:11 2008
@@ -151,6 +151,7 @@
 class raw_fd_ostream : public raw_ostream {
   int FD;
   bool ShouldClose;
+  uint64_t pos;
 public:
   /// raw_fd_ostream - Open the specified file for writing. If an
   /// error occurs, information about the error is put into ErrorInfo,
@@ -178,7 +179,9 @@
   void close();
   
   /// tell - Return the current offset with the file.
-  uint64_t tell();
+  uint64_t tell() {
+    return pos + (OutBufCur - OutBufStart);
+  }  
 };
   
 /// raw_stdout_ostream - This is a stream that always prints to stdout.

Modified: llvm/trunk/lib/Support/raw_ostream.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/raw_ostream.cpp?rev=60560&r1=60559&r2=60560&view=diff

==============================================================================
--- llvm/trunk/lib/Support/raw_ostream.cpp (original)
+++ llvm/trunk/lib/Support/raw_ostream.cpp Thu Dec  4 16:51:11 2008
@@ -202,7 +202,7 @@
 /// stream should be immediately destroyed; the string will be empty
 /// if no error occurred.
 raw_fd_ostream::raw_fd_ostream(const char *Filename, bool Binary,
-                               std::string &ErrorInfo) {
+                               std::string &ErrorInfo) : pos(0) {
   ErrorInfo.clear();
 
   // Handle "-" as stdout.
@@ -240,8 +240,10 @@
 
 void raw_fd_ostream::flush_impl() {
   assert (FD >= 0 && "File already closed.");
-  if (OutBufCur-OutBufStart)
+  if (OutBufCur-OutBufStart) {
+    pos += (OutBufCur - OutBufStart);
     ::write(FD, OutBufStart, OutBufCur-OutBufStart);
+  }
   HandleFlush();
 }
 
@@ -253,14 +255,6 @@
   FD = -1;
 }
 
-uint64_t raw_fd_ostream::tell() {
-  // We have to take into account the bytes waiting in the buffer.  For now
-  // we do the easy thing and just flush the buffer before getting the
-  // current file offset.
-  flush();  
-  return (uint64_t) lseek(FD, 0, SEEK_CUR);
-}
-
 //===----------------------------------------------------------------------===//
 //  raw_stdout/err_ostream
 //===----------------------------------------------------------------------===//





More information about the llvm-commits mailing list