diff options
Diffstat (limited to 'decoder.h')
-rw-r--r-- | decoder.h | 20 |
1 files changed, 12 insertions, 8 deletions
@@ -26,6 +26,7 @@ class Range_decoder uint32_t range; const int infd; // input file descriptor bool at_stream_end; + bool nonzero_; bool read_block(); @@ -42,11 +43,12 @@ public: code( 0 ), range( 0xFFFFFFFFU ), infd( ifd ), - at_stream_end( false ) + at_stream_end( false ), nonzero_( false ) {} ~Range_decoder() { delete[] buffer; } + bool nonzero() const { return nonzero_; } unsigned get_code() const { return code; } bool finished() { return pos >= stream_pos && !read_block(); } @@ -110,8 +112,10 @@ public: { code = 0; range = 0xFFFFFFFFU; - // check first byte of the LZMA stream - if( get_byte() != 0 && !ignore_nonzero ) return false; + // check first byte of the LZMA stream without reading it + nonzero_ = buffer[pos] != 0; + if( nonzero_ && !ignore_nonzero ) return false; + get_byte(); // discard first byte of the LZMA stream for( int i = 0; i < 4; ++i ) code = ( code << 8 ) | get_byte(); return true; } @@ -131,7 +135,7 @@ public: range >>= 1; // symbol <<= 1; // if( code >= range ) { code -= range; symbol |= 1; } - const bool bit = ( code >= range ); + const bool bit = code >= range; symbol <<= 1; symbol += bit; code -= range & ( 0U - bit ); } @@ -329,14 +333,14 @@ class LZ_decoder bool fast, fast2; if( lpos > distance ) { - fast = ( len < dictionary_size - lpos ); - fast2 = ( fast && len <= lpos - i ); + fast = len < dictionary_size - lpos; + fast2 = fast && len <= lpos - i; } else { i += dictionary_size; - fast = ( len < dictionary_size - i ); // (i == pos) may happen - fast2 = ( fast && len <= i - lpos ); + fast = len < dictionary_size - i; // (i == pos) may happen + fast2 = fast && len <= i - lpos; } if( fast ) // no wrap { |