From d6911b86bea2132ffae3d3841d35c4215e6b4609 Mon Sep 17 00:00:00 2001 From: senhuang42 Date: Wed, 7 Oct 2020 23:44:36 -0400 Subject: [PATCH] Require LDM matches to be strictly greater in length --- lib/compress/zstd_opt.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/lib/compress/zstd_opt.c b/lib/compress/zstd_opt.c index 8ba7aba38..e55c459de 100644 --- a/lib/compress/zstd_opt.c +++ b/lib/compress/zstd_opt.c @@ -867,20 +867,9 @@ static void ZSTD_optLdm_maybeAddMatch(ZSTD_match_t* matches, U32* nbMatches, return; } - DEBUGLOG(6, "ZSTD_optLdm_maybeAddMatch(): Adding ldm candidate match (offCode: %u matchLength %u) at block position=%u", - candidateOffCode, candidateMatchLength, currPosInBlock); - if (*nbMatches == 0) { - matches[*nbMatches].len = candidateMatchLength; - matches[*nbMatches].off = candidateOffCode; - (*nbMatches)++; - } else if ((candidateMatchLength >= matches[*nbMatches-1].len) && *nbMatches < ZSTD_OPT_NUM) { - 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; - } + if (*nbMatches == 0 || ((candidateMatchLength > matches[*nbMatches-1].len) && *nbMatches < ZSTD_OPT_NUM)) { + DEBUGLOG(6, "ZSTD_optLdm_maybeAddMatch(): Adding ldm candidate match (offCode: %u matchLength %u) at block position=%u", + candidateOffCode, candidateMatchLength, currPosInBlock); matches[*nbMatches].len = candidateMatchLength; matches[*nbMatches].off = candidateOffCode; (*nbMatches)++; -- 2.47.2