Skip to content

Commit

Permalink
Track Step Size Statefully, Rather than Recalculating Every Time
Browse files Browse the repository at this point in the history
  • Loading branch information
felixhandte committed Sep 1, 2021
1 parent 80bc12b commit bc768bc
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/compress/zstd_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -348,8 +355,10 @@ ZSTD_compressBlock_fast_generic_pipelined(

/* 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;
Expand Down

0 comments on commit bc768bc

Please sign in to comment.