summaryrefslogtreecommitdiffstats
path: root/encoder.cc
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 07:23:06 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 07:23:06 +0000
commit4b650df10dcb0f7aa36b40f517e3ddb85b1198e4 (patch)
tree41c04636a5e74aa432e5f44d5904e805cae51790 /encoder.cc
parentAdding debian version 1.6~pre1-1. (diff)
downloadlzip-4b650df10dcb0f7aa36b40f517e3ddb85b1198e4.tar.xz
lzip-4b650df10dcb0f7aa36b40f517e3ddb85b1198e4.zip
Merging upstream version 1.6~pre2.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'encoder.cc')
-rw-r--r--encoder.cc39
1 files changed, 37 insertions, 2 deletions
diff --git a/encoder.cc b/encoder.cc
index f1a033b..291f1d1 100644
--- a/encoder.cc
+++ b/encoder.cc
@@ -43,6 +43,41 @@ bool Matchfinder::read_block() throw()
}
+Matchfinder::Matchfinder( const int dict_size, const int len_limit,
+ const int ides )
+ :
+ partial_data_pos( 0 ),
+ pos( 0 ),
+ cyclic_pos( 0 ),
+ stream_pos( 0 ),
+ ides_( ides ),
+ match_len_limit_( len_limit ),
+ prev_positions( new int32_t[num_prev_positions] ),
+ at_stream_end( false )
+ {
+ const int buffer_size_limit = ( 2 * dict_size ) +
+ max_num_trials + max_match_len;
+ buffer_size = std::max( 65536, dict_size );
+ buffer = (uint8_t *)std::malloc( buffer_size );
+ if( !buffer ) throw std::bad_alloc();
+ if( !read_block() ) throw Error( "read error" );
+ if( !at_stream_end && buffer_size < buffer_size_limit )
+ {
+ buffer_size = buffer_size_limit;
+ buffer = (uint8_t *)std::realloc( buffer, buffer_size );
+ if( !buffer ) throw std::bad_alloc();
+ if( !read_block() ) throw Error( "read error" );
+ }
+ if( at_stream_end && stream_pos < dict_size )
+ dictionary_size_ = std::max( min_dictionary_size, stream_pos );
+ else dictionary_size_ = dict_size;
+ pos_limit = buffer_size;
+ if( !at_stream_end ) pos_limit -= max_match_len;
+ prev_pos_tree = new int32_t[2*dictionary_size_];
+ for( int i = 0; i < num_prev_positions; ++i ) prev_positions[i] = -1;
+ }
+
+
bool Matchfinder::reset() throw()
{
const int size = stream_pos - pos;
@@ -433,7 +468,7 @@ void LZ_encoder::flush( const State & state )
trailer.data_size( matchfinder.data_position() );
trailer.member_size( range_encoder.member_position() + sizeof trailer );
for( unsigned int i = 0; i < sizeof trailer; ++i )
- range_encoder.put_byte( (( uint8_t *)&trailer)[i] );
+ range_encoder.put_byte( ((uint8_t *)&trailer)[i] );
range_encoder.flush_data();
}
@@ -453,7 +488,7 @@ LZ_encoder::LZ_encoder( Matchfinder & mf, const File_header & header,
fill_align_prices();
for( unsigned int i = 0; i < sizeof header; ++i )
- range_encoder.put_byte( (( uint8_t *)&header)[i] );
+ range_encoder.put_byte( ((uint8_t *)&header)[i] );
}