From 0c515590d81efd2f6655a0f0c992ab33ff76bcdd Mon Sep 17 00:00:00 2001 From: senhuang42 Date: Tue, 6 Oct 2020 13:44:44 -0400 Subject: [PATCH] Replace offCode of largest match if ldm's offCode is superior --- lib/compress/zstd_opt.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/compress/zstd_opt.c b/lib/compress/zstd_opt.c index 0baba0b18..80b8e28c9 100644 --- a/lib/compress/zstd_opt.c +++ b/lib/compress/zstd_opt.c @@ -874,8 +874,11 @@ static void ZSTD_optLdm_maybeAddMatch(ZSTD_match_t* matches, U32* nbMatches, matches[*nbMatches].off = candidateOffCode; (*nbMatches)++; } else if ((candidateMatchLength >= matches[*nbMatches-1].len) && *nbMatches < ZSTD_OPT_NUM) { - /* No need to insert the match if it's the exact same, or offCode is larger with same matchLen */ - if (candidateMatchLength == matches[*nbMatches-1].len && candidateOffCode >= matches[*nbMatches-1].off) { + if (candidateMatchLength == matches[*nbMatches-1].len) { + /* No need to insert match with same matchLength. At most, replace offCode if it is smaller. */ + if (candidateOffCode < matches[*nbMatches-1].off) { + matches[*nbMatches-1].off = candidateOffCode; + } return; } matches[*nbMatches].len = candidateMatchLength; -- 2.47.2