From 335919a42c9d2c18d4d2ea7e05fb78f45f4c7114 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 10 Nov 2017 13:27:28 +0000 Subject: [PATCH] Add a fast path when skipping bytes in a file-based I/O reader. --- renderdoc/serialise/streamio.h | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/renderdoc/serialise/streamio.h b/renderdoc/serialise/streamio.h index 4143cd607..6716f3f5c 100644 --- a/renderdoc/serialise/streamio.h +++ b/renderdoc/serialise/streamio.h @@ -157,7 +157,26 @@ public: return true; } - bool SkipBytes(uint64_t numBytes) { return Read(NULL, numBytes); } + bool SkipBytes(uint64_t numBytes) + { + // fast path for file skipping + if(m_File && numBytes > Available()) + { + // first, completely exhaust the buffer + numBytes -= Available(); + Read(NULL, Available()); + + // then just seek for the rest + FileIO::fseek64(m_File, numBytes, SEEK_CUR); + m_ReadOffset += numBytes; + + // the next read will re-fill the buffer, just the same as if we'd done a perfectly sized read + return true; + } + + return Read(NULL, numBytes); + } + // compile-time constant element to let the compiler inline the memcpy template bool Read(T &data)