]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Replace offCode of largest match if ldm's offCode is superior
authorsenhuang42 <senhuang96@fb.com>
Tue, 6 Oct 2020 17:44:44 +0000 (13:44 -0400)
committersenhuang42 <senhuang96@fb.com>
Wed, 7 Oct 2020 17:56:25 +0000 (13:56 -0400)
lib/compress/zstd_opt.c

index 0baba0b18f22d5f88964faf53eb1812c0ec764c4..80b8e28c972579ca295ee65c489b71bd7986907e 100644 (file)
@@ -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;