From edfcd768ba394150df34d59f08765c3e061e6c72 Mon Sep 17 00:00:00 2001 From: Giulio Camuffo Date: Sat, 26 Jan 2013 19:00:22 +0100 Subject: COMMON: Make BufferedSeekableReadStream use the buffer with SEEK_SET and SEEK_END --- common/stream.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'common/stream.cpp') diff --git a/common/stream.cpp b/common/stream.cpp index 85647bfe3a..d3cfce4066 100644 --- a/common/stream.cpp +++ b/common/stream.cpp @@ -379,12 +379,25 @@ BufferedSeekableReadStream::BufferedSeekableReadStream(SeekableReadStream *paren bool BufferedSeekableReadStream::seek(int32 offset, int whence) { // If it is a "local" seek, we may get away with "seeking" around // in the buffer only. - // Note: We could try to handle SEEK_END and SEEK_SET, too, but - // since they are rarely used, it seems not worth the effort. _eos = false; // seeking always cancels EOS - if (whence == SEEK_CUR && (int)_pos + offset >= 0 && _pos + offset <= _bufSize) { - _pos += offset; + int relOffset = 0; + switch (whence) { + case SEEK_SET: + relOffset = offset - pos(); + break; + case SEEK_CUR: + relOffset = offset; + break; + case SEEK_END: + relOffset = (size() + offset) - pos(); + break; + default: + break; + } + + if ((int)_pos + relOffset >= 0 && _pos + relOffset <= _bufSize) { + _pos += relOffset; // Note: we do not need to reset parent's eos flag here. It is // sufficient that it is reset when actually seeking in the parent. -- cgit v1.2.3