From ca89f7679881aeb2ce056592f5d38531db2465fd Mon Sep 17 00:00:00 2001 From: richiesams Date: Sun, 7 Jul 2013 11:31:05 -0500 Subject: ZVISION: Move early break out above the for loop. LzssReadStream::decompressBytes() The other code would go through each of the for loops and do nothing due to EOS. --- engines/zvision/lzss_read_stream.cpp | 74 ++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/engines/zvision/lzss_read_stream.cpp b/engines/zvision/lzss_read_stream.cpp index 69b49c596c..61b5b16393 100644 --- a/engines/zvision/lzss_read_stream.cpp +++ b/engines/zvision/lzss_read_stream.cpp @@ -52,49 +52,49 @@ void LzssReadStream::decompressBytes(uint32 numberOfBytes) { while (!_source->eos() && bytesRead <= numberOfBytes) { byte flagbyte = _source->readByte(); + if (_source->eos()) + break; byte mask = 1; for (uint32 i = 0; i < 8; i++) { - if (!_source->eos()) { - if ((flagbyte & mask) == mask) + if ((flagbyte & mask) == mask) + { + byte data = _source->readByte(); + bytesRead++; + if (_source->eos()) + break; + + _window[_windowCursor] = data; + _destination.push_back(data); + + // Increment and wrap the window cursor + _windowCursor = (_windowCursor + 1) & 0xFFF; + } + else + { + byte low = _source->readByte(); + bytesRead++; + if (_source->eos()) + break; + + byte high = _source->readByte(); + bytesRead++; + if (_source->eos()) + break; + + uint16 length = (high & 0xF) + 2; + uint16 offset = low | ((high & 0xF0)<<4); + + for(byte j = 0; j <= length; j++) { - byte data = _source->readByte(); - bytesRead++; - if (_source->eos()) - break; - - _window[_windowCursor] = data; - _destination.push_back(data); - - // Increment and wrap the window cursor + byte temp = _window[(offset + j) & 0xFFF]; + _window[_windowCursor] = temp; + _destination.push_back(temp); _windowCursor = (_windowCursor + 1) & 0xFFF; } - else - { - byte low = _source->readByte(); - bytesRead++; - if (_source->eos()) - break; - - byte high = _source->readByte(); - bytesRead++; - if (_source->eos()) - break; - - uint16 length = (high & 0xF) + 2; - uint16 offset = low | ((high & 0xF0)<<4); - - for(byte j = 0; j <= length; j++) - { - byte temp = _window[(offset + j) & 0xFFF]; - _window[_windowCursor] = temp; - _destination.push_back(temp); - _windowCursor = (_windowCursor + 1) & 0xFFF; - } - }; - - mask = mask << 1; - } + }; + + mask = mask << 1; } } } -- cgit v1.2.3