From 54878fa0cdaa5af70dae4d9eb872e990e69a5022 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 25 Jan 2021 13:43:58 +0100 Subject: Merging upstream version 1.12. Signed-off-by: Daniel Baumann --- encoder.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) (limited to 'encoder.c') diff --git a/encoder.c b/encoder.c index 202b8cf..ceb8a97 100644 --- a/encoder.c +++ b/encoder.c @@ -1,18 +1,18 @@ -/* Clzip - LZMA lossless data compressor - Copyright (C) 2010-2019 Antonio Diaz Diaz. +/* Clzip - LZMA lossless data compressor + Copyright (C) 2010-2021 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 - the Free Software Foundation, either version 2 of the License, or - (at your option) any later version. + 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 + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program. If not, see . + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ #define _FILE_OFFSET_BITS 64 @@ -37,7 +37,7 @@ int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs ) int32_t * ptr1 = ptr0 + 1; int32_t * newptr; int len = 0, len0 = 0, len1 = 0; - int maxlen = 0; + int maxlen = 3; /* only used if pairs != 0 */ int num_pairs = 0; const int pos1 = e->eb.mb.pos + 1; const int min_pos = ( e->eb.mb.pos > e->eb.mb.dictionary_size ) ? @@ -62,8 +62,8 @@ int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs ) if( pairs ) { - int np2 = e->eb.mb.prev_positions[key2]; - int np3 = e->eb.mb.prev_positions[key3]; + const int np2 = e->eb.mb.prev_positions[key2]; + const int np3 = e->eb.mb.prev_positions[key3]; if( np2 > min_pos && e->eb.mb.buffer[np2-1] == data[0] ) { pairs[0].dis = e->eb.mb.pos - np2; @@ -73,19 +73,17 @@ int LZe_get_match_pairs( struct LZ_encoder * const e, struct Pair * pairs ) if( np2 != np3 && np3 > min_pos && e->eb.mb.buffer[np3-1] == data[0] ) { maxlen = 3; - np2 = np3; - pairs[num_pairs].dis = e->eb.mb.pos - np2; - ++num_pairs; + pairs[num_pairs++].dis = e->eb.mb.pos - np3; } if( num_pairs > 0 ) { - const int delta = pos1 - np2; + const int delta = pairs[num_pairs-1].dis + 1; while( maxlen < len_limit && data[maxlen-delta] == data[maxlen] ) ++maxlen; pairs[num_pairs-1].len = maxlen; + if( maxlen < 3 ) maxlen = 3; if( maxlen >= len_limit ) pairs = 0; /* done. now just skip */ } - if( maxlen < 3 ) maxlen = 3; } e->eb.mb.prev_positions[key2] = pos1; -- cgit v1.2.3