summaryrefslogtreecommitdiffstats
path: root/mtester.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2017-05-07 15:53:12 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2017-05-07 15:53:12 +0000
commit217f007824bd69712dada24a431c0f703d515fa3 (patch)
treef9e719e5800eda365dae0baf81f11a20467ac07f /mtester.cc
parentReleasing debian version 1.18-5. (diff)
downloadlziprecover-217f007824bd69712dada24a431c0f703d515fa3.tar.xz
lziprecover-217f007824bd69712dada24a431c0f703d515fa3.zip
Merging upstream version 1.19.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'mtester.cc')
-rw-r--r--mtester.cc118
1 files changed, 53 insertions, 65 deletions
diff --git a/mtester.cc b/mtester.cc
index 22fd67d..6b3e048 100644
--- a/mtester.cc
+++ b/mtester.cc
@@ -1,5 +1,5 @@
/* Lziprecover - Data recovery tool for the lzip format
- Copyright (C) 2009-2016 Antonio Diaz Diaz.
+ Copyright (C) 2009-2017 Antonio Diaz Diaz.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -113,25 +113,23 @@ int LZ_mtester::test_member( const unsigned long pos_limit )
const int pos_state = data_position() & pos_state_mask;
if( rdec.decode_bit( bm_match[state()][pos_state] ) == 0 ) // 1st bit
{
- const uint8_t prev_byte = peek_prev();
- if( state.is_char() )
- {
- state.set_char1();
- put_byte( rdec.decode_tree8( bm_literal[get_lit_state(prev_byte)] ) );
- }
+ Bit_model * const bm = bm_literal[get_lit_state(peek_prev())];
+ if( state.is_char_set_char() )
+ put_byte( rdec.decode_tree8( bm ) );
else
- {
- state.set_char2();
- put_byte( rdec.decode_matched( bm_literal[get_lit_state(prev_byte)],
- peek( rep0 ) ) );
- }
+ put_byte( rdec.decode_matched( bm, peek( rep0 ) ) );
}
- else
+ else // match or repeated match
{
int len;
if( rdec.decode_bit( bm_rep[state()] ) != 0 ) // 2nd bit
{
- if( rdec.decode_bit( bm_rep0[state()] ) != 0 ) // 3rd bit
+ if( rdec.decode_bit( bm_rep0[state()] ) == 0 ) // 3rd bit
+ {
+ if( rdec.decode_bit( bm_len[state()][pos_state] ) == 0 ) // 4th bit
+ { state.set_short_rep(); put_byte( peek( rep0 ) ); continue; }
+ }
+ else
{
unsigned distance;
if( rdec.decode_bit( bm_rep1[state()] ) == 0 ) // 4th bit
@@ -147,34 +145,28 @@ int LZ_mtester::test_member( const unsigned long pos_limit )
rep1 = rep0;
rep0 = distance;
}
- else
- {
- if( rdec.decode_bit( bm_len[state()][pos_state] ) == 0 ) // 4th bit
- { state.set_short_rep(); put_byte( peek( rep0 ) ); continue; }
- }
state.set_rep();
len = min_match_len + rdec.decode_len( rep_len_model, pos_state );
}
- else
+ else // match
{
- const unsigned rep0_saved = rep0;
len = min_match_len + rdec.decode_len( match_len_model, pos_state );
- const int dis_slot = rdec.decode_tree6( bm_dis_slot[get_len_state(len)] );
- if( dis_slot < start_dis_model ) rep0 = dis_slot;
- else
+ unsigned distance = rdec.decode_tree6( bm_dis_slot[get_len_state(len)] );
+ if( distance >= start_dis_model )
{
+ const unsigned dis_slot = distance;
const int direct_bits = ( dis_slot >> 1 ) - 1;
- rep0 = ( 2 | ( dis_slot & 1 ) ) << direct_bits;
+ distance = ( 2 | ( dis_slot & 1 ) ) << direct_bits;
if( dis_slot < end_dis_model )
- rep0 += rdec.decode_tree_reversed( bm_dis + rep0 - dis_slot - 1,
- direct_bits );
+ distance += rdec.decode_tree_reversed(
+ bm_dis + ( distance - dis_slot ), direct_bits );
else
{
- rep0 += rdec.decode( direct_bits - dis_align_bits ) << dis_align_bits;
- rep0 += rdec.decode_tree_reversed4( bm_align );
- if( rep0 == 0xFFFFFFFFU ) // marker found
+ distance +=
+ rdec.decode( direct_bits - dis_align_bits ) << dis_align_bits;
+ distance += rdec.decode_tree_reversed4( bm_align );
+ if( distance == 0xFFFFFFFFU ) // marker found
{
- rep0 = rep0_saved;
rdec.normalize();
flush_data();
if( len == min_match_len ) // End Of Stream marker
@@ -183,10 +175,10 @@ int LZ_mtester::test_member( const unsigned long pos_limit )
}
return 4;
}
- if( rep0 > max_rep0 ) max_rep0 = rep0;
+ if( distance > max_rep0 ) max_rep0 = distance;
}
}
- rep3 = rep2; rep2 = rep1; rep1 = rep0_saved;
+ rep3 = rep2; rep2 = rep1; rep1 = rep0; rep0 = distance;
state.set_match();
if( rep0 >= dictionary_size || ( rep0 >= pos && !pos_wrapped ) )
{ flush_data(); return 1; }
@@ -212,11 +204,10 @@ int LZ_mtester::debug_decode_member( const long long dpos, const long long mpos,
const int pos_state = data_position() & pos_state_mask;
if( rdec.decode_bit( bm_match[state()][pos_state] ) == 0 ) // 1st bit
{
- const uint8_t prev_byte = peek_prev();
- if( state.is_char() )
+ Bit_model * const bm = bm_literal[get_lit_state(peek_prev())];
+ if( state.is_char_set_char() )
{
- state.set_char1();
- const uint8_t cur_byte = rdec.decode_tree8( bm_literal[get_lit_state(prev_byte)] );
+ const uint8_t cur_byte = rdec.decode_tree8( bm );
put_byte( cur_byte );
if( show_packets )
std::printf( "%6llu %6llu literal %s\n",
@@ -224,10 +215,8 @@ int LZ_mtester::debug_decode_member( const long long dpos, const long long mpos,
}
else
{
- state.set_char2();
const uint8_t match_byte = peek( rep0 );
- const uint8_t cur_byte =
- rdec.decode_matched( bm_literal[get_lit_state(prev_byte)], match_byte );
+ const uint8_t cur_byte = rdec.decode_matched( bm, match_byte );
put_byte( cur_byte );
if( show_packets )
std::printf( "%6llu %6llu literal %s, match byte %6llu %s\n",
@@ -241,7 +230,18 @@ int LZ_mtester::debug_decode_member( const long long dpos, const long long mpos,
if( rdec.decode_bit( bm_rep[state()] ) != 0 ) // 2nd bit
{
int rep = 0;
- if( rdec.decode_bit( bm_rep0[state()] ) != 0 ) // 3rd bit
+ if( rdec.decode_bit( bm_rep0[state()] ) == 0 ) // 3rd bit
+ {
+ if( rdec.decode_bit( bm_len[state()][pos_state] ) == 0 ) // 4th bit
+ {
+ if( show_packets )
+ std::printf( "%6llu %6llu shortrep %s %6u (%6llu)\n",
+ mp, dp, format_byte( peek( rep0 ) ),
+ rep0 + 1, dp - rep0 - 1 );
+ state.set_short_rep(); put_byte( peek( rep0 ) ); continue;
+ }
+ }
+ else
{
unsigned distance;
if( rdec.decode_bit( bm_rep1[state()] ) == 0 ) // 4th bit
@@ -257,17 +257,6 @@ int LZ_mtester::debug_decode_member( const long long dpos, const long long mpos,
rep1 = rep0;
rep0 = distance;
}
- else
- {
- if( rdec.decode_bit( bm_len[state()][pos_state] ) == 0 ) // 4th bit
- {
- if( show_packets )
- std::printf( "%6llu %6llu shortrep %s %6u (%6llu)\n",
- mp, dp, format_byte( peek( rep0 ) ),
- rep0 + 1, dp - rep0 - 1 );
- state.set_short_rep(); put_byte( peek( rep0 ) ); continue;
- }
- }
state.set_rep();
len = min_match_len + rdec.decode_len( rep_len_model, pos_state );
if( show_packets )
@@ -276,24 +265,23 @@ int LZ_mtester::debug_decode_member( const long long dpos, const long long mpos,
}
else // match
{
- const unsigned rep0_saved = rep0;
len = min_match_len + rdec.decode_len( match_len_model, pos_state );
- const int dis_slot = rdec.decode_tree6( bm_dis_slot[get_len_state(len)] );
- if( dis_slot < start_dis_model ) rep0 = dis_slot;
- else
+ unsigned distance = rdec.decode_tree6( bm_dis_slot[get_len_state(len)] );
+ if( distance >= start_dis_model )
{
+ const unsigned dis_slot = distance;
const int direct_bits = ( dis_slot >> 1 ) - 1;
- rep0 = ( 2 | ( dis_slot & 1 ) ) << direct_bits;
+ distance = ( 2 | ( dis_slot & 1 ) ) << direct_bits;
if( dis_slot < end_dis_model )
- rep0 += rdec.decode_tree_reversed( bm_dis + rep0 - dis_slot - 1,
- direct_bits );
+ distance += rdec.decode_tree_reversed(
+ bm_dis + ( distance - dis_slot ), direct_bits );
else
{
- rep0 += rdec.decode( direct_bits - dis_align_bits ) << dis_align_bits;
- rep0 += rdec.decode_tree_reversed4( bm_align );
- if( rep0 == 0xFFFFFFFFU ) // marker found
+ distance +=
+ rdec.decode( direct_bits - dis_align_bits ) << dis_align_bits;
+ distance += rdec.decode_tree_reversed4( bm_align );
+ if( distance == 0xFFFFFFFFU ) // marker found
{
- rep0 = rep0_saved;
rdec.normalize();
flush_data();
if( show_packets )
@@ -313,10 +301,10 @@ int LZ_mtester::debug_decode_member( const long long dpos, const long long mpos,
}
return 4;
}
- if( rep0 > max_rep0 ) max_rep0 = rep0;
+ if( distance > max_rep0 ) max_rep0 = distance;
}
}
- rep3 = rep2; rep2 = rep1; rep1 = rep0_saved;
+ rep3 = rep2; rep2 = rep1; rep1 = rep0; rep0 = distance;
state.set_match();
if( show_packets )
std::printf( "%6llu %6llu match %6u,%3d (%6lld)",