]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Write Back Advanced Hash in Long Matches as Well (+Ratio)
authorW. Felix Handte <w@felixhandte.com>
Wed, 8 Sep 2021 16:45:42 +0000 (12:45 -0400)
committerW. Felix Handte <w@felixhandte.com>
Tue, 5 Oct 2021 18:54:37 +0000 (14:54 -0400)
Since we're now hashing the position ahead even if we find a long match and
don't search that next position, we can write it back into the hashtable even
in long matches. This seems to cost us no speed, and improves compression
ratio slightly!

lib/compress/zstd_double_fast.c

index 45770b886b976120b197442f32b5463889ee52f7..2e310e3223f816dc350744e2d131f95ba934e8d0 100644 (file)
@@ -204,6 +204,12 @@ _search_next_long:
         while (((ip>anchor) & (matchs0>prefixLowest)) && (ip[-1] == matchs0[-1])) { ip--; matchs0--; mLength++; } /* catch up */
     }
 
+    /* fall-through */
+
+_match_found: /* requires ip, offset, mLength */
+    offset_2 = offset_1;
+    offset_1 = offset;
+
     if (step < 4) {
         /* It is unsafe to write this value back to the hashtable when ip1 is
          * greater than or equal to the new ip we will have after we're done
@@ -215,12 +221,6 @@ _search_next_long:
         hashLong[hl1] = (U32)(ip1 - base);
     }
 
-    /* fall-through */
-
-_match_found: /* requires ip, offset, mLength */
-    offset_2 = offset_1;
-    offset_1 = offset;
-
     ZSTD_storeSeq(seqStore, (size_t)(ip-anchor), anchor, iend, offset + ZSTD_REP_MOVE, mLength-MINMATCH);
 
 _match_stored: