summaryrefslogtreecommitdiffstats
path: root/encoder.cc
diff options
context:
space:
mode:
authorDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 13:45:30 +0000
committerDaniel Baumann <mail@daniel-baumann.ch>2015-11-07 13:45:30 +0000
commitb8470619016a1f87a6d2db4ce1857608dbd2fb21 (patch)
tree5dff6f0557f7da575ab9c0ace0c8bc8b0e80fc81 /encoder.cc
parentAdding debian version 1.1-4. (diff)
downloadlzlib-b8470619016a1f87a6d2db4ce1857608dbd2fb21.tar.xz
lzlib-b8470619016a1f87a6d2db4ce1857608dbd2fb21.zip
Merging upstream version 1.2.
Signed-off-by: Daniel Baumann <mail@daniel-baumann.ch>
Diffstat (limited to 'encoder.cc')
-rw-r--r--encoder.cc44
1 files changed, 30 insertions, 14 deletions
diff --git a/encoder.cc b/encoder.cc
index a0001c1..fb7e65e 100644
--- a/encoder.cc
+++ b/encoder.cc
@@ -353,22 +353,23 @@ int LZ_encoder::sequence_optimizer( const int reps[num_rep_distances],
return 1;
}
- {
- const int normal_match_price = match_price + price0( bm_rep[state()] );
- int len = min_match_len;
if( main_len <= replens[rep_index] )
{
main_len = replens[rep_index];
- for( ; len <= main_len; ++len ) trials[len].price = infinite_price;
+ for( int len = min_match_len; len <= main_len; ++len )
+ trials[len].price = infinite_price;
}
- else for( ; len <= main_len; ++len )
+ else
{
- trials[len].dis = match_distances[len] + num_rep_distances;
- trials[len].prev_index = 0;
- trials[len].price = normal_match_price +
- price_pair( match_distances[len], len, pos_state );
+ const int normal_match_price = match_price + price0( bm_rep[state()] );
+ for( int len = min_match_len; len <= main_len; ++len )
+ {
+ trials[len].dis = match_distances[len] + num_rep_distances;
+ trials[len].prev_index = 0;
+ trials[len].price = normal_match_price +
+ price_pair( match_distances[len], len, pos_state );
+ }
}
- }
for( int rep = 0; rep < num_rep_distances; ++rep )
{
@@ -474,10 +475,25 @@ int LZ_encoder::sequence_optimizer( const int reps[num_rep_distances],
while( num_trials < cur + newlen )
trials[++num_trials].price = infinite_price;
- for( int len = min_match_len; len <= newlen; ++len )
- trials[cur+len].update( match_distances[len] + num_rep_distances, cur,
- normal_match_price +
- price_pair( match_distances[len], len, pos_state ) );
+ int dis = match_distances[min_match_len];
+ int dis_state = get_dis_state( min_match_len );
+ int dis_price = infinite_price;
+ if( dis < modeled_distances )
+ trials[cur+min_match_len].update( dis + num_rep_distances, cur,
+ normal_match_price + dis_prices[dis_state][dis] +
+ len_encoder.price( min_match_len, pos_state ) );
+ for( int len = min_match_len + 1; len <= newlen; ++len )
+ {
+ if( dis != match_distances[len] || dis_state < max_dis_states - 1 )
+ {
+ dis = match_distances[len];
+ dis_state = get_dis_state( len );
+ dis_price = price_dis( dis, dis_state );
+ }
+ trials[cur+len].update( dis + num_rep_distances, cur,
+ normal_match_price + dis_price +
+ len_encoder.price( len, pos_state ) );
+ }
}
}
}