llvm.org GIT mirror llvm / d75ba1c
Have raw_fd_ostream keep track of the position in the file to make tell() go faster by not requiring a flush(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60560 91177308-0d34-0410-b5e6-96231b3b80d8 Ted Kremenek 11 years ago
2 changed file(s) with 8 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
150150 class raw_fd_ostream : public raw_ostream {
151151 int FD;
152152 bool ShouldClose;
153 uint64_t pos;
153154 public:
154155 /// raw_fd_ostream - Open the specified file for writing. If an
155156 /// error occurs, information about the error is put into ErrorInfo,
177178 void close();
178179
179180 /// tell - Return the current offset with the file.
180 uint64_t tell();
181 uint64_t tell() {
182 return pos + (OutBufCur - OutBufStart);
183 }
181184 };
182185
183186 /// raw_stdout_ostream - This is a stream that always prints to stdout.
201201 /// stream should be immediately destroyed; the string will be empty
202202 /// if no error occurred.
203203 raw_fd_ostream::raw_fd_ostream(const char *Filename, bool Binary,
204 std::string &ErrorInfo) {
204 std::string &ErrorInfo) : pos(0) {
205205 ErrorInfo.clear();
206206
207207 // Handle "-" as stdout.
239239
240240 void raw_fd_ostream::flush_impl() {
241241 assert (FD >= 0 && "File already closed.");
242 if (OutBufCur-OutBufStart)
242 if (OutBufCur-OutBufStart) {
243 pos += (OutBufCur - OutBufStart);
243244 ::write(FD, OutBufStart, OutBufCur-OutBufStart);
245 }
244246 HandleFlush();
245247 }
246248
250252 flush();
251253 ::close(FD);
252254 FD = -1;
253 }
254
255 uint64_t raw_fd_ostream::tell() {
256 // We have to take into account the bytes waiting in the buffer. For now
257 // we do the easy thing and just flush the buffer before getting the
258 // current file offset.
259 flush();
260 return (uint64_t) lseek(FD, 0, SEEK_CUR);
261255 }
262256
263257 //===----------------------------------------------------------------------===//