diff options
Diffstat (limited to 'common/zlib.cpp')
-rw-r--r-- | common/zlib.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/common/zlib.cpp b/common/zlib.cpp index 920338e57e..c22ea1e660 100644 --- a/common/zlib.cpp +++ b/common/zlib.cpp @@ -8,12 +8,12 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. @@ -27,6 +27,8 @@ #include "common/ptr.h" #include "common/util.h" #include "common/stream.h" +#include "common/debug.h" +#include "common/textconsole.h" #if defined(USE_ZLIB) #ifdef __SYMBIAN32__ @@ -139,6 +141,10 @@ bool inflateZlibInstallShield(byte *dst, uint dstLen, const byte *src, uint srcL return true; } +#ifndef RELEASE_BUILD +static bool _shownBackwardSeekingWarning = false; +#endif + /** * A simple wrapper class which can be used to wrap around an arbitrary * other SeekableReadStream and will then provide on-the-fly decompression support. @@ -241,13 +247,17 @@ public: } bool seek(int32 offset, int whence = SEEK_SET) { int32 newPos = 0; - assert(whence != SEEK_END); // SEEK_END not supported switch (whence) { case SEEK_SET: newPos = offset; break; case SEEK_CUR: newPos = _pos + offset; + break; + case SEEK_END: + // NOTE: This can be an expensive operation (see below). + newPos = size() + offset; + break; } assert(newPos >= 0); @@ -256,9 +266,17 @@ public: // To search backward, we have to restart the whole decompression // from the start of the file. A rather wasteful operation, best // to avoid it. :/ -#if DEBUG - warning("Backward seeking in GZipReadStream detected"); + +#ifndef RELEASE_BUILD + if (!_shownBackwardSeekingWarning) { + // We only throw this warning once per stream, to avoid + // getting the console swarmed with warnings when consecutive + // seeks are made. + debug(1, "Backward seeking in GZipReadStream detected"); + _shownBackwardSeekingWarning = true; + } #endif + _pos = 0; _wrapped->seek(0, SEEK_SET); _zlibErr = inflateReset(&_stream); |