From f249597dfd35ef3972c06fb4cf52bbc8939ed0d4 Mon Sep 17 00:00:00 2001 From: Emmanuel Marty Date: Tue, 29 Oct 2019 12:09:14 +0100 Subject: [PATCH] Increase LZSA2 ratio --- src/shrink_block_v2.c | 18 ++++++------------ src/shrink_context.h | 4 ++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/shrink_block_v2.c b/src/shrink_block_v2.c index e52f9de..b06b01f 100644 --- a/src/shrink_block_v2.c +++ b/src/shrink_block_v2.c @@ -222,15 +222,6 @@ static void lzsa_insert_forward_match_v2(lzsa_compressor *pCompressor, const uns lzsa_insert_forward_match_v2(pCompressor, pInWindow, nRepPos, nMatchOffset, nEndOffset, nDepth + 1); } - else if (!exists && r >= NMATCHES_PER_INDEX_V2) { - for (r = NMATCHES_PER_INDEX_V2 - 1; r >= 0; r--) { - if (fwd_match[r].length < nRepLen) { - fwd_match[r].offset = nMatchOffset; - fwd_match[r].length = nRepLen; - break; - } - } - } } } } @@ -378,19 +369,20 @@ static void lzsa_optimize_forward_v2(lzsa_compressor *pCompressor, const unsigne if (nRepCodingChoiceCost <= pDestSlots[NMATCHES_PER_ARRIVAL - 1].cost) { if (nCodingChoiceCost <= pDestSlots[NMATCHES_PER_ARRIVAL - 1].cost) { int exists = 0; + int nScore = arrival[(i << MATCHES_PER_ARRIVAL_SHIFT) + j].score + ((nMatchOffset == nRepOffset) ? 2 : 3); for (n = 0; n < NMATCHES_PER_ARRIVAL && pDestSlots[n].cost <= nCodingChoiceCost; n++) { - if (pDestSlots[n].rep_offset == nMatchOffset) { + if (pDestSlots[n].rep_offset == nMatchOffset && + (!nInsertForwardReps || pDestSlots[n].cost != nCodingChoiceCost || pDestSlots[n].rep_pos >= i || nScore >= (pDestSlots[n].score + nDisableScore) || + pDestSlots[NMATCHES_PER_ARRIVAL - 1].from_slot)) { exists = 1; break; } } if (!exists) { - int nScore = arrival[(i << MATCHES_PER_ARRIVAL_SHIFT) + j].score + ((nMatchOffset == nRepOffset) ? 2 : 3); - for (n = 0; n < NMATCHES_PER_ARRIVAL; n++) { lzsa_arrival *pDestArrival = &pDestSlots[n]; @@ -1018,6 +1010,8 @@ int lzsa_optimize_and_write_block_v2(lzsa_compressor *pCompressor, const unsigne /* Compress optimally without breaking ties in favor of less tokens */ lzsa_optimize_forward_v2(pCompressor, pInWindow, pCompressor->best_match, nPreviousBlockSize, nPreviousBlockSize + nInDataSize, 0 /* reduce */, (nInDataSize < 65536) ? 1 : 0 /* insert forward reps */); + if (nInDataSize < 65536) + lzsa_optimize_forward_v2(pCompressor, pInWindow, pCompressor->best_match, nPreviousBlockSize, nPreviousBlockSize + nInDataSize, 0 /* reduce */, 1 /* insert forward reps */); int nDidReduce; int nPasses = 0; diff --git a/src/shrink_context.h b/src/shrink_context.h index 7ac3284..a6a442f 100644 --- a/src/shrink_context.h +++ b/src/shrink_context.h @@ -55,8 +55,8 @@ extern "C" { #define NMATCHES_PER_INDEX_V1 8 #define MATCHES_PER_INDEX_SHIFT_V1 3 -#define NMATCHES_PER_INDEX_V2 32 -#define MATCHES_PER_INDEX_SHIFT_V2 5 +#define NMATCHES_PER_INDEX_V2 64 +#define MATCHES_PER_INDEX_SHIFT_V2 6 #define LEAVE_ALONE_MATCH_SIZE 1000