summaryrefslogtreecommitdiffstats
path: root/fast_encoder.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2017-05-07 15:49:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2017-05-07 15:49:03 +0000
commit1adf9f41888bd0630227a02cf387f6b5d9a13227 (patch)
tree6eb2672c16756c89f04790466061ce12e9b46f86 /fast_encoder.c
parentAdding upstream version 1.8. (diff)
downloadclzip-1adf9f41888bd0630227a02cf387f6b5d9a13227.tar.xz
clzip-1adf9f41888bd0630227a02cf387f6b5d9a13227.zip
Adding upstream version 1.9.upstream/1.9
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'fast_encoder.c')
-rw-r--r--fast_encoder.c44
1 files changed, 18 insertions, 26 deletions
diff --git a/fast_encoder.c b/fast_encoder.c
index 941c0e2..399cc1a 100644
--- a/fast_encoder.c
+++ b/fast_encoder.c
@@ -1,5 +1,5 @@
/* Clzip - LZMA lossless data compressor
- Copyright (C) 2010-2016 Antonio Diaz Diaz.
+ Copyright (C) 2010-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
@@ -33,21 +33,22 @@ int FLZe_longest_match_len( struct FLZ_encoder * const fe, int * const distance
enum { len_limit = 16 };
const uint8_t * const data = Mb_ptr_to_current_pos( &fe->eb.mb );
int32_t * ptr0 = fe->eb.mb.pos_array + fe->eb.mb.cyclic_pos;
- int32_t * newptr;
const int pos1 = fe->eb.mb.pos + 1;
- int maxlen = 0;
- int count, delta, newpos;
- if( len_limit > Mb_available_bytes( &fe->eb.mb ) ) return 0;
+ int maxlen = 0, newpos1, count;
+ const int available = min( Mb_available_bytes( &fe->eb.mb ), max_match_len );
+ if( available < len_limit ) return 0;
fe->key4 = ( ( fe->key4 << 4 ) ^ data[3] ) & fe->eb.mb.key4_mask;
- newpos = fe->eb.mb.prev_positions[fe->key4];
+ newpos1 = fe->eb.mb.prev_positions[fe->key4];
fe->eb.mb.prev_positions[fe->key4] = pos1;
for( count = 4; ; )
{
- if( --count < 0 || newpos <= 0 ) { *ptr0 = 0; break; }
- delta = pos1 - newpos;
- if( delta > fe->eb.mb.dictionary_size ) { *ptr0 = 0; break; }
+ int32_t * newptr;
+ int delta;
+ if( newpos1 <= 0 || --count < 0 ||
+ ( delta = pos1 - newpos1 ) > fe->eb.mb.dictionary_size )
+ { *ptr0 = 0; break; }
newptr = fe->eb.mb.pos_array +
( fe->eb.mb.cyclic_pos - delta +
( ( fe->eb.mb.cyclic_pos >= delta ) ? 0 : fe->eb.mb.dictionary_size + 1 ) );
@@ -55,23 +56,15 @@ int FLZe_longest_match_len( struct FLZ_encoder * const fe, int * const distance
if( data[maxlen-delta] == data[maxlen] )
{
int len = 0;
- while( len < len_limit && data[len-delta] == data[len] ) ++len;
- if( maxlen < len ) { maxlen = len; *distance = delta - 1; }
+ while( len < available && data[len-delta] == data[len] ) ++len;
+ if( maxlen < len )
+ { maxlen = len; *distance = delta - 1;
+ if( maxlen >= len_limit ) { *ptr0 = *newptr; break; } }
}
- if( maxlen < len_limit )
- {
- *ptr0 = newpos;
- ptr0 = newptr;
- newpos = *ptr0;
- }
- else
- {
- *ptr0 = *newptr;
- maxlen += Mb_true_match_len( &fe->eb.mb, maxlen, *distance + 1,
- max_match_len - maxlen );
- break;
- }
+ *ptr0 = newpos1;
+ ptr0 = newptr;
+ newpos1 = *ptr0;
}
return maxlen;
}
@@ -112,8 +105,7 @@ bool FLZe_encode_member( struct FLZ_encoder * const fe,
for( i = 0; i < num_rep_distances; ++i )
{
- const int tlen = Mb_true_match_len( &fe->eb.mb, 0,
- reps[i] + 1, max_match_len );
+ const int tlen = Mb_true_match_len( &fe->eb.mb, 0, reps[i] + 1 );
if( tlen > len ) { len = tlen; rep = i; }
}
if( len > min_match_len && len + 3 > main_len )