diff options
author | Arne H Juul <arnej@yahoo-inc.com> | 2017-05-09 09:01:21 +0200 |
---|---|---|
committer | Arne H Juul <arnej@yahoo-inc.com> | 2017-05-09 09:01:21 +0200 |
commit | 54e4075b5d67786422c99f3e306ebc4fd36faec3 (patch) | |
tree | b2d4858e179c95fbcc32f47d4098a49dcbaf94e3 /fbench | |
parent | f32fbffad65d3f2b2b29c96596dbf27f70282992 (diff) |
fix FileReader bugs
* Reset() and SetFilePos() should flush old buffer
* make GetFilePos() work immediately after SetFilePos()
* refactor Reset() to use SetFilePos()
* refactor FindNewLine() to use GetFilePos()
* remove useless GetBufPos()
Diffstat (limited to 'fbench')
-rw-r--r-- | fbench/src/util/filereader.cpp | 14 | ||||
-rw-r--r-- | fbench/src/util/filereader.h | 4 |
2 files changed, 6 insertions, 12 deletions
diff --git a/fbench/src/util/filereader.cpp b/fbench/src/util/filereader.cpp index 30469e18e0c..b4c1c18a7d3 100644 --- a/fbench/src/util/filereader.cpp +++ b/fbench/src/util/filereader.cpp @@ -50,17 +50,15 @@ bool FileReader::Reset() { _file->clear(); - _file->seekg(0); - _nextReadPos = 0; - return bool(*_file); + return SetFilePos(0); } bool FileReader::SetFilePos(int64_t pos) { - _bufpos = 0; + _bufused = _bufpos = 0; + _lastReadPos = _nextReadPos = pos; _file->seekg(pos); - _nextReadPos = pos; return bool(*_file); } @@ -76,10 +74,8 @@ FileReader::FindNewline(int64_t pos) { char buf[100]; SetFilePos(pos); - ssize_t len = ReadLine(buf, 100); - ++_bufpos; - - return pos+len; + ReadLine(buf, 100); + return GetFilePos(); } void diff --git a/fbench/src/util/filereader.h b/fbench/src/util/filereader.h index 6b85ad3ba51..a0ec794836a 100644 --- a/fbench/src/util/filereader.h +++ b/fbench/src/util/filereader.h @@ -96,10 +96,8 @@ public: int64_t GetFileSize(); /** - * @returns _bufpos + * @return current position in file **/ - uint64_t GetBufPos() const { return _bufpos; } - uint64_t GetFilePos() const { return _lastReadPos + _bufpos; } /** |