From 3b16f37e66431499212f97458130744bc2b8cb37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Tue, 4 Feb 2020 21:47:31 +0100 Subject: [PATCH] Some micro-optimizatoins and code cleanup --- src/map/IMG/bitstream.cpp | 11 +++-------- src/map/IMG/subfile.cpp | 14 -------------- src/map/IMG/subfile.h | 15 ++++++++++++++- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/src/map/IMG/bitstream.cpp b/src/map/IMG/bitstream.cpp index 4e72351c..3d619834 100644 --- a/src/map/IMG/bitstream.cpp +++ b/src/map/IMG/bitstream.cpp @@ -50,18 +50,13 @@ bool BitStream4::read(int bits, quint32 &val) return true; } - quint32 old = 0; - if (_used < 32) { - old = (_data << _used) >> (32 - bits); - bits = (bits - 32) + _used; - } - _used = bits; - - quint32 bytes = qMin(_length, (quint32)4); + quint32 old = (_used < 32) ? (_data << _used) >> (32 - bits) : 0; + quint32 bytes = qMin(_length, 4U); if (!_file.readVUInt32SW(_hdl, bytes, _data)) return false; + _used -= 32 - bits; _length -= bytes; _unused = (4 - bytes) * 8; _data <<= _unused; diff --git a/src/map/IMG/subfile.cpp b/src/map/IMG/subfile.cpp index 5da65683..7820fb97 100644 --- a/src/map/IMG/subfile.cpp +++ b/src/map/IMG/subfile.cpp @@ -69,20 +69,6 @@ bool SubFile::readVUInt32(Handle &hdl, quint32 &val) const return true; } -bool SubFile::readVUInt32SW(Handle &hdl, quint32 bytes, quint32 &val) const -{ - quint8 b; - - val = 0; - for (quint32 i = bytes; i; i--) { - if (!readByte(hdl, b)) - return false; - val |= ((quint32)b) << ((i-1) * 8); - } - - return true; -} - bool SubFile::readVBitfield32(Handle &hdl, quint32 &bitfield) const { quint8 bits; diff --git a/src/map/IMG/subfile.h b/src/map/IMG/subfile.h index 5c8ba74b..c987c886 100644 --- a/src/map/IMG/subfile.h +++ b/src/map/IMG/subfile.h @@ -97,8 +97,21 @@ public: return true; } + bool readVUInt32SW(Handle &hdl, quint32 bytes, quint32 &val) const + { + quint8 b; + + val = 0; + for (quint32 i = bytes; i; i--) { + if (!readByte(hdl, b)) + return false; + val |= ((quint32)b) << ((i-1) * 8); + } + + return true; + } + bool readVUInt32(Handle &hdl, quint32 &val) const; - bool readVUInt32SW(Handle &hdl, quint32 bytes, quint32 &val) const; bool readVBitfield32(Handle &hdl, quint32 &bitfield) const; quint16 offset() const {return _blocks->first();}