"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "encoder_base.c" between
lzlib-1.12.tar.lz and lzlib-1.13.tar.lz

About: Lzlib is a data compression library providing in-memory LZMA compression and decompression functions using the lzip format.

encoder_base.c  (lzlib-1.12.tar.lz):encoder_base.c  (lzlib-1.13.tar.lz)
/* Lzlib - Compression library for the lzip format /* Lzlib - Compression library for the lzip format
Copyright (C) 2009-2021 Antonio Diaz Diaz. Copyright (C) 2009-2022 Antonio Diaz Diaz.
This library is free software. Redistribution and use in source and This library is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided binary forms, with or without modification, are permitted provided
that the following conditions are met: that the following conditions are met:
1. Redistributions of source code must retain the above copyright 1. Redistributions of source code must retain the above copyright
notice, this list of conditions, and the following disclaimer. notice, this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright 2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the following disclaimer in the notice, this list of conditions, and the following disclaimer in the
skipping to change at line 49 skipping to change at line 49
return true; return true;
} }
static bool Mb_init( struct Matchfinder_base * const mb, const int before_size, static bool Mb_init( struct Matchfinder_base * const mb, const int before_size,
const int dict_size, const int after_size, const int dict_size, const int after_size,
const int dict_factor, const int num_prev_positions23, const int dict_factor, const int num_prev_positions23,
const int pos_array_factor ) const int pos_array_factor )
{ {
const int buffer_size_limit = const int buffer_size_limit =
( dict_factor * dict_size ) + before_size + after_size; ( dict_factor * dict_size ) + before_size + after_size;
unsigned size;
int i; int i;
mb->partial_data_pos = 0; mb->partial_data_pos = 0;
mb->before_size = before_size; mb->before_size = before_size;
mb->after_size = after_size; mb->after_size = after_size;
mb->pos = 0; mb->pos = 0;
mb->cyclic_pos = 0; mb->cyclic_pos = 0;
mb->stream_pos = 0; mb->stream_pos = 0;
mb->num_prev_positions23 = num_prev_positions23; mb->num_prev_positions23 = num_prev_positions23;
mb->at_stream_end = false; mb->at_stream_end = false;
mb->sync_flush_pending = false; mb->sync_flush_pending = false;
mb->buffer_size = max( 65536, buffer_size_limit ); mb->buffer_size = max( 65536, buffer_size_limit );
mb->buffer = (uint8_t *)malloc( mb->buffer_size ); mb->buffer = (uint8_t *)malloc( mb->buffer_size );
if( !mb->buffer ) return false; if( !mb->buffer ) return false;
mb->saved_dictionary_size = dict_size; mb->saved_dictionary_size = dict_size;
mb->dictionary_size = dict_size; mb->dictionary_size = dict_size;
mb->pos_limit = mb->buffer_size - after_size; mb->pos_limit = mb->buffer_size - after_size;
size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 ); unsigned size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 );
if( mb->dictionary_size > 1 << 26 ) /* 64 MiB */ if( mb->dictionary_size > 1 << 26 ) size >>= 1; /* 64 MiB */
size >>= 1;
mb->key4_mask = size - 1; /* increases with dictionary size */ mb->key4_mask = size - 1; /* increases with dictionary size */
size += num_prev_positions23; size += num_prev_positions23;
mb->num_prev_positions = size; mb->num_prev_positions = size;
mb->pos_array_size = pos_array_factor * ( mb->dictionary_size + 1 ); mb->pos_array_size = pos_array_factor * ( mb->dictionary_size + 1 );
size += mb->pos_array_size; size += mb->pos_array_size;
if( size * sizeof mb->prev_positions[0] <= size ) mb->prev_positions = 0; if( size * sizeof mb->prev_positions[0] <= size ) mb->prev_positions = 0;
else mb->prev_positions = else mb->prev_positions =
(int32_t *)malloc( size * sizeof mb->prev_positions[0] ); (int32_t *)malloc( size * sizeof mb->prev_positions[0] );
if( !mb->prev_positions ) { free( mb->buffer ); return false; } if( !mb->prev_positions ) { free( mb->buffer ); return false; }
mb->pos_array = mb->prev_positions + mb->num_prev_positions; mb->pos_array = mb->prev_positions + mb->num_prev_positions;
for( i = 0; i < mb->num_prev_positions; ++i ) mb->prev_positions[i] = 0; for( i = 0; i < mb->num_prev_positions; ++i ) mb->prev_positions[i] = 0;
return true; return true;
} }
static void Mb_adjust_array( struct Matchfinder_base * const mb ) static void Mb_adjust_array( struct Matchfinder_base * const mb )
{ {
int size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 ); int size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 );
if( mb->dictionary_size > 1 << 26 ) /* 64 MiB */ if( mb->dictionary_size > 1 << 26 ) size >>= 1; /* 64 MiB */
size >>= 1;
mb->key4_mask = size - 1; mb->key4_mask = size - 1;
size += mb->num_prev_positions23; size += mb->num_prev_positions23;
mb->num_prev_positions = size; mb->num_prev_positions = size;
mb->pos_array = mb->prev_positions + mb->num_prev_positions; mb->pos_array = mb->prev_positions + mb->num_prev_positions;
} }
static void Mb_adjust_dictionary_size( struct Matchfinder_base * const mb ) static void Mb_adjust_dictionary_size( struct Matchfinder_base * const mb )
{ {
if( mb->stream_pos < mb->dictionary_size ) if( mb->stream_pos < mb->dictionary_size )
{ {
skipping to change at line 127 skipping to change at line 124
mb->sync_flush_pending = false; mb->sync_flush_pending = false;
mb->dictionary_size = mb->saved_dictionary_size; mb->dictionary_size = mb->saved_dictionary_size;
Mb_adjust_array( mb ); Mb_adjust_array( mb );
mb->pos_limit = mb->buffer_size - mb->after_size; mb->pos_limit = mb->buffer_size - mb->after_size;
for( i = 0; i < mb->num_prev_positions; ++i ) mb->prev_positions[i] = 0; for( i = 0; i < mb->num_prev_positions; ++i ) mb->prev_positions[i] = 0;
} }
/* End Of Stream marker => (dis == 0xFFFFFFFFU, len == min_match_len) */ /* End Of Stream marker => (dis == 0xFFFFFFFFU, len == min_match_len) */
static void LZeb_try_full_flush( struct LZ_encoder_base * const eb ) static void LZeb_try_full_flush( struct LZ_encoder_base * const eb )
{ {
int i;
const int pos_state = Mb_data_position( &eb->mb ) & pos_state_mask;
const State state = eb->state;
Lzip_trailer trailer;
if( eb->member_finished || if( eb->member_finished ||
Cb_free_bytes( &eb->renc.cb ) < max_marker_size + eb->renc.ff_count + Lt_s ize ) Cb_free_bytes( &eb->renc.cb ) < max_marker_size + eb->renc.ff_count + Lt_s ize )
return; return;
eb->member_finished = true; eb->member_finished = true;
const int pos_state = Mb_data_position( &eb->mb ) & pos_state_mask;
const State state = eb->state;
Re_encode_bit( &eb->renc, &eb->bm_match[state][pos_state], 1 ); Re_encode_bit( &eb->renc, &eb->bm_match[state][pos_state], 1 );
Re_encode_bit( &eb->renc, &eb->bm_rep[state], 0 ); Re_encode_bit( &eb->renc, &eb->bm_rep[state], 0 );
LZeb_encode_pair( eb, 0xFFFFFFFFU, min_match_len, pos_state ); LZeb_encode_pair( eb, 0xFFFFFFFFU, min_match_len, pos_state );
Re_flush( &eb->renc ); Re_flush( &eb->renc );
Lzip_trailer trailer;
Lt_set_data_crc( trailer, LZeb_crc( eb ) ); Lt_set_data_crc( trailer, LZeb_crc( eb ) );
Lt_set_data_size( trailer, Mb_data_position( &eb->mb ) ); Lt_set_data_size( trailer, Mb_data_position( &eb->mb ) );
Lt_set_member_size( trailer, Re_member_position( &eb->renc ) + Lt_size ); Lt_set_member_size( trailer, Re_member_position( &eb->renc ) + Lt_size );
int i;
for( i = 0; i < Lt_size; ++i ) for( i = 0; i < Lt_size; ++i )
Cb_put_byte( &eb->renc.cb, trailer[i] ); Cb_put_byte( &eb->renc.cb, trailer[i] );
} }
/* Sync Flush marker => (dis == 0xFFFFFFFFU, len == min_match_len + 1) */ /* Sync Flush marker => (dis == 0xFFFFFFFFU, len == min_match_len + 1) */
static void LZeb_try_sync_flush( struct LZ_encoder_base * const eb ) static void LZeb_try_sync_flush( struct LZ_encoder_base * const eb )
{ {
const int pos_state = Mb_data_position( &eb->mb ) & pos_state_mask;
const State state = eb->state;
const unsigned min_size = eb->renc.ff_count + max_marker_size; const unsigned min_size = eb->renc.ff_count + max_marker_size;
if( eb->member_finished || if( eb->member_finished ||
Cb_free_bytes( &eb->renc.cb ) < min_size + max_marker_size ) return; Cb_free_bytes( &eb->renc.cb ) < min_size + max_marker_size ) return;
eb->mb.sync_flush_pending = false; eb->mb.sync_flush_pending = false;
const unsigned long long old_mpos = Re_member_position( &eb->renc ); const unsigned long long old_mpos = Re_member_position( &eb->renc );
const int pos_state = Mb_data_position( &eb->mb ) & pos_state_mask;
const State state = eb->state;
do { /* size of markers must be >= rd_min_available_bytes + 5 */ do { /* size of markers must be >= rd_min_available_bytes + 5 */
Re_encode_bit( &eb->renc, &eb->bm_match[state][pos_state], 1 ); Re_encode_bit( &eb->renc, &eb->bm_match[state][pos_state], 1 );
Re_encode_bit( &eb->renc, &eb->bm_rep[state], 0 ); Re_encode_bit( &eb->renc, &eb->bm_rep[state], 0 );
LZeb_encode_pair( eb, 0xFFFFFFFFU, min_match_len + 1, pos_state ); LZeb_encode_pair( eb, 0xFFFFFFFFU, min_match_len + 1, pos_state );
Re_flush( &eb->renc ); Re_flush( &eb->renc );
} }
while( Re_member_position( &eb->renc ) - old_mpos < min_size ); while( Re_member_position( &eb->renc ) - old_mpos < min_size );
} }
static void LZeb_reset( struct LZ_encoder_base * const eb, static void LZeb_reset( struct LZ_encoder_base * const eb,
 End of changes. 10 change blocks. 
13 lines changed or deleted 10 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)