From bc768bccc036fe0d60ff63fe240dfca7474636d9 Mon Sep 17 00:00:00 2001 From: "W. Felix Handte" Date: Wed, 18 Aug 2021 12:47:14 -0400 Subject: [PATCH] Track Step Size Statefully, Rather than Recalculating Every Time --- lib/compress/zstd_fast.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/compress/zstd_fast.c b/lib/compress/zstd_fast.c index fa214e63..ff2faab3 100644 --- a/lib/compress/zstd_fast.c +++ b/lib/compress/zstd_fast.c @@ -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;