diff options
Diffstat (limited to 'mtester.h')
-rw-r--r-- | mtester.h | 47 |
1 files changed, 25 insertions, 22 deletions
@@ -194,14 +194,13 @@ class LZ_mtester unsigned long long partial_data_pos; Range_mtester rdec; const unsigned dictionary_size; - const int buffer_size; - uint8_t * buffer; /* output buffer */ - int pos; /* current pos in buffer */ - int stream_pos; /* first byte not yet written to file */ + uint8_t * buffer; // output buffer + unsigned pos; // current pos in buffer + unsigned stream_pos; // first byte not yet written to file uint32_t crc_; - unsigned rep0; /* rep[0-3] latest four distances */ - unsigned rep1; /* used for efficient coding of */ - unsigned rep2; /* repeated distances */ + unsigned rep0; // rep[0-3] latest four distances + unsigned rep1; // used for efficient coding of + unsigned rep2; // repeated distances unsigned rep3; State state; @@ -225,37 +224,42 @@ class LZ_mtester uint8_t peek_prev() const { - const int i = ( ( pos > 0 ) ? pos : buffer_size ) - 1; + const unsigned i = ( ( pos > 0 ) ? pos : dictionary_size ) - 1; return buffer[i]; } - uint8_t peek( const int distance ) const + uint8_t peek( const unsigned distance ) const { - int i = pos - distance - 1; - if( i < 0 ) i += buffer_size; + unsigned i = pos - distance - 1; + if( pos <= distance ) i += dictionary_size; return buffer[i]; } void put_byte( const uint8_t b ) { buffer[pos] = b; - if( ++pos >= buffer_size ) flush_data(); + if( ++pos >= dictionary_size ) flush_data(); } - void copy_block( const int distance, int len ) + void copy_block( const unsigned distance, unsigned len ) { - int i = pos - distance - 1; - if( i < 0 ) i += buffer_size; - if( len < buffer_size - std::max( pos, i ) && len <= std::abs( pos - i ) ) + unsigned i = pos - distance - 1; + bool fast; + if( pos <= distance ) + { i += dictionary_size; + fast = ( len <= dictionary_size - i && len <= i - pos ); } + else + fast = ( len < dictionary_size - pos && len <= pos - i ); + if( fast ) // no wrap, no overlap { - std::memcpy( buffer + pos, buffer + i, len ); // no wrap, no overlap + std::memcpy( buffer + pos, buffer + i, len ); pos += len; } else for( ; len > 0; --len ) { buffer[pos] = buffer[i]; - if( ++pos >= buffer_size ) flush_data(); - if( ++i >= buffer_size ) i = 0; + if( ++pos >= dictionary_size ) flush_data(); + if( ++i >= dictionary_size ) i = 0; } } @@ -268,8 +272,7 @@ public: partial_data_pos( 0 ), rdec( ibuf, ibuf_size ), dictionary_size( dict_size ), - buffer_size( std::max( 65536U, dictionary_size ) ), - buffer( new uint8_t[buffer_size] ), + buffer( new uint8_t[dictionary_size] ), pos( 0 ), stream_pos( 0 ), crc_( 0xFFFFFFFFU ), @@ -277,7 +280,7 @@ public: rep1( 0 ), rep2( 0 ), rep3( 0 ) - { buffer[buffer_size-1] = 0; } // prev_byte of first byte + { buffer[dictionary_size-1] = 0; } // prev_byte of first byte ~LZ_mtester() { delete[] buffer; } |