From 3caa72c722291ac5d102513dd127ee894691e020 Mon Sep 17 00:00:00 2001 From: emmanuel-marty Date: Sat, 11 May 2019 11:42:18 +0200 Subject: [PATCH] Clarify optimizer --- src/format.h | 2 ++ src/shrink_v1.c | 2 +- src/shrink_v2.c | 11 ++++------- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/format.h b/src/format.h index c9534fa..108811c 100755 --- a/src/format.h +++ b/src/format.h @@ -36,6 +36,8 @@ #define MIN_OFFSET 1 #define MAX_OFFSET 0xffff +#define MAX_VARLEN 0xffff + #define MIN_MATCH_SIZE_V1 3 #define LITERALS_RUN_LEN_V1 7 #define MATCH_RUN_LEN_V1 15 diff --git a/src/shrink_v1.c b/src/shrink_v1.c index 1ca3918..55d63fd 100644 --- a/src/shrink_v1.c +++ b/src/shrink_v1.c @@ -314,7 +314,7 @@ static int lzsa_optimize_command_count_v1(lsza_compressor *pCompressor, const in else { if ((i + nMatchLen) < nEndOffset && nMatchLen >= LCP_MAX && pMatch->offset && pMatch->offset <= 32 && pCompressor->match[(i + nMatchLen) << MATCHES_PER_OFFSET_SHIFT].offset == pMatch->offset && (nMatchLen % pMatch->offset) == 0 && - (nMatchLen + pCompressor->match[(i + nMatchLen) << MATCHES_PER_OFFSET_SHIFT].length) <= MAX_OFFSET) { + (nMatchLen + pCompressor->match[(i + nMatchLen) << MATCHES_PER_OFFSET_SHIFT].length) <= MAX_VARLEN) { /* Join */ pMatch->length += pCompressor->match[(i + nMatchLen) << MATCHES_PER_OFFSET_SHIFT].length; diff --git a/src/shrink_v2.c b/src/shrink_v2.c index 27b8d76..6cb3a14 100644 --- a/src/shrink_v2.c +++ b/src/shrink_v2.c @@ -208,19 +208,16 @@ static void lzsa_optimize_matches_v2(lsza_compressor *pCompressor, const int nSt int nLiteralsLen = nLastLiteralsOffset - i; nLiteralsCost = 8 + cost[i + 1]; + + /* Add to the cost of encoding literals as their number crosses a variable length encoding boundary. + * The cost automatically accumulates down the chain. */ if (nLiteralsLen == LITERALS_RUN_LEN_V2) { - /* Add to the cost of encoding literals as their number crosses a variable length encoding boundary. - * The cost automatically accumulates down the chain. */ nLiteralsCost += 4; } else if (nLiteralsLen == (LITERALS_RUN_LEN_V2 + 15)) { - /* Add to the cost of encoding literals as their number crosses a variable length encoding boundary. - * The cost automatically accumulates down the chain. */ nLiteralsCost += 8; } else if (nLiteralsLen == 256) { - /* Add to the cost of encoding literals as their number crosses a variable length encoding boundary. - * The cost automatically accumulates down the chain. */ nLiteralsCost += 16; } if (pCompressor->best_match[i + 1].length >= MIN_MATCH_SIZE_V2) @@ -527,7 +524,7 @@ static int lzsa_optimize_command_count_v2(lsza_compressor *pCompressor, const in else { if ((i + nMatchLen) < nEndOffset && nMatchLen >= LCP_MAX && pMatch->offset && pMatch->offset <= 32 && pCompressor->best_match[i + nMatchLen].offset == pMatch->offset && (nMatchLen % pMatch->offset) == 0 && - (nMatchLen + pCompressor->best_match[i + nMatchLen].length) <= MAX_OFFSET) { + (nMatchLen + pCompressor->best_match[i + nMatchLen].length) <= MAX_VARLEN) { /* Join */ pMatch->length += pCompressor->best_match[i + nMatchLen].length;