ReaderLcf: Optimize out calls to seekg() for small values
MODIFY
src/reader_lcf.cpp
src/reader_lcf.cpp
@@ -198,14 +198,23 @@ bool LcfReader::Eof() const {
}
void LcfReader::Seek(size_t pos, SeekMode mode) {
+ constexpr auto fast_seek_size = 32;
switch (mode) {
case LcfReader::FromStart:
stream.seekg(pos, std::ios_base::beg);
offset = stream.tellg();
break;
case LcfReader::FromCurrent:
+ if (pos <= fast_seek_size) {
+ // seekg() always results in a system call which is slow.
+ // For small values just read and throwaway.
+ char buf[fast_seek_size];
+ stream.read(buf, pos);
+ offset += stream.gcount();
+ } else {
stream.seekg(pos, std::ios_base::cur);
offset = stream.tellg();
+ }
break;
case LcfReader::FromEnd:
stream.seekg(pos, std::ios_base::end);

ReaderLcf: Optimize out calls to seekg() for small values