summaryrefslogtreecommitdiffstats
path: root/encoder_base.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2018-02-13 07:03:45 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2018-02-13 07:04:01 +0000
commit39b772cbf3d797f755f5b1fdb133fea1bedc8178 (patch)
treeaa09ba82ec4995be3d883f18c3a4f80959869f01 /encoder_base.c
parentReleasing debian version 1.9-5. (diff)
downloadlzlib-39b772cbf3d797f755f5b1fdb133fea1bedc8178.tar.xz
lzlib-39b772cbf3d797f755f5b1fdb133fea1bedc8178.zip
Merging upstream version 1.10.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'encoder_base.c')
-rw-r--r--encoder_base.c49
1 files changed, 28 insertions, 21 deletions
diff --git a/encoder_base.c b/encoder_base.c
index be9af5d..0dbc617 100644
--- a/encoder_base.c
+++ b/encoder_base.c
@@ -1,5 +1,5 @@
/* Lzlib - Compression library for the lzip format
- Copyright (C) 2009-2017 Antonio Diaz Diaz.
+ Copyright (C) 2009-2018 Antonio Diaz Diaz.
This library is free software. Redistribution and use in source and
binary forms, with or without modification, are permitted provided
@@ -39,39 +39,39 @@ static bool Mb_normalize_pos( struct Matchfinder_base * const mb )
}
-static bool Mb_init( struct Matchfinder_base * const mb,
- const int before, const int dict_size,
- const int after_size, const int dict_factor,
- const int num_prev_positions23,
+static bool Mb_init( struct Matchfinder_base * const mb, const int before_size,
+ const int dict_size, const int after_size,
+ const int dict_factor, const int num_prev_positions23,
const int pos_array_factor )
{
const int buffer_size_limit =
- ( dict_factor * dict_size ) + before + after_size;
+ ( dict_factor * dict_size ) + before_size + after_size;
unsigned size;
int i;
mb->partial_data_pos = 0;
- mb->before_size = before;
+ mb->before_size = before_size;
mb->after_size = after_size;
mb->pos = 0;
mb->cyclic_pos = 0;
mb->stream_pos = 0;
+ mb->num_prev_positions23 = num_prev_positions23;
mb->at_stream_end = false;
mb->flushing = false;
mb->buffer_size = max( 65536, buffer_size_limit );
mb->buffer = (uint8_t *)malloc( mb->buffer_size );
if( !mb->buffer ) return false;
+ mb->saved_dictionary_size = dict_size;
mb->dictionary_size = dict_size;
mb->pos_limit = mb->buffer_size - after_size;
size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 );
if( mb->dictionary_size > 1 << 26 ) /* 64 MiB */
size >>= 1;
mb->key4_mask = size - 1;
- mb->num_prev_positions23 = num_prev_positions23;
size += num_prev_positions23;
-
mb->num_prev_positions = size;
+
mb->pos_array_size = pos_array_factor * ( mb->dictionary_size + 1 );
size += mb->pos_array_size;
if( size * sizeof mb->prev_positions[0] <= size ) mb->prev_positions = 0;
@@ -84,21 +84,25 @@ static bool Mb_init( 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 );
+ if( mb->dictionary_size > 1 << 26 ) /* 64 MiB */
+ size >>= 1;
+ mb->key4_mask = size - 1;
+ size += mb->num_prev_positions23;
+ mb->num_prev_positions = size;
+ mb->pos_array = mb->prev_positions + mb->num_prev_positions;
+ }
+
+
static void Mb_adjust_dictionary_size( struct Matchfinder_base * const mb )
{
if( mb->stream_pos < mb->dictionary_size )
{
- int size;
- mb->buffer_size =
- mb->dictionary_size =
- mb->pos_limit = max( min_dictionary_size, mb->stream_pos );
- size = 1 << max( 16, real_bits( mb->dictionary_size - 1 ) - 2 );
- if( mb->dictionary_size > 1 << 26 ) /* 64 MiB */
- size >>= 1;
- mb->key4_mask = size - 1;
- size += mb->num_prev_positions23;
- mb->num_prev_positions = size;
- mb->pos_array = mb->prev_positions + mb->num_prev_positions;
+ mb->dictionary_size = max( min_dictionary_size, mb->stream_pos );
+ Mb_adjust_array( mb );
+ mb->pos_limit = mb->buffer_size;
}
}
@@ -114,6 +118,9 @@ static void Mb_reset( struct Matchfinder_base * const mb )
mb->cyclic_pos = 0;
mb->at_stream_end = false;
mb->flushing = false;
+ mb->dictionary_size = mb->saved_dictionary_size;
+ Mb_adjust_array( mb );
+ mb->pos_limit = mb->buffer_size - mb->after_size;
for( i = 0; i < mb->num_prev_positions; ++i ) mb->prev_positions[i] = 0;
}
@@ -180,7 +187,7 @@ static void LZeb_reset( struct LZ_encoder_base * const eb,
Bm_array_init( eb->bm_align, dis_align_size );
Lm_init( &eb->match_len_model );
Lm_init( &eb->rep_len_model );
- Re_reset( &eb->renc );
+ Re_reset( &eb->renc, eb->mb.dictionary_size );
for( i = 0; i < num_rep_distances; ++i ) eb->reps[i] = 0;
eb->state = 0;
eb->member_finished = false;