]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Track Step Size Statefully, Rather than Recalculating Every Time
authorW. Felix Handte <w@felixhandte.com>
Wed, 18 Aug 2021 16:47:14 +0000 (12:47 -0400)
committerW. Felix Handte <w@felixhandte.com>
Wed, 1 Sep 2021 18:15:03 +0000 (14:15 -0400)
lib/compress/zstd_fast.c

index fa214e63d67a299f38e7dc6da1f198e61779d857..ff2faab33fd253a2493918456305a4da89bc6b52 100644 (file)
@@ -268,6 +268,10 @@ ZSTD_compressBlock_fast_generic_pipelined(
     const BYTE* match0;
     size_t mLength;
 
+    size_t step;
+    const BYTE* nextStep;
+    const size_t kStepIncr = (1 << (kSearchStrength - 1));
+
     DEBUGLOG(5, "ZSTD_compressBlock_fast_generic_pipelined");
     ip0 += (ip0 == prefixStart);
     {   U32 const curr = (U32)(ip0 - base);
@@ -280,6 +284,9 @@ ZSTD_compressBlock_fast_generic_pipelined(
     /* start each op */
 _start: /* Requires: ip0 */
 
+    step = stepSize;
+    nextStep = ip0 + kStepIncr;
+
     /* calculate positions, ip0 - anchor == 0, so we skip step calc */
     ip1 = ip0 + stepSize;
     ip2 = ip1 + stepSize;
@@ -348,8 +355,10 @@ _start: /* Requires: ip0 */
 
         /* advance to next positions */
         {
-            size_t const step = ((size_t)(ip2 - anchor) >> (kSearchStrength - 1)) + stepSize;
-            assert(step >= 1);
+            if (ip2 >= nextStep) {
+                step++;
+                nextStep += kStepIncr;
+            }
 
             idx0 = idx1;
             idx1 = idx2;