Skip to content

Commit

Permalink
rewrite code in the manner suggested by @terrelln
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyan4973 committed Oct 17, 2024
1 parent 61d08b0 commit 47d4f56
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions lib/compress/zstd_double_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,23 +254,21 @@ size_t ZSTD_compressBlock_doubleFast_noDict_generic(

/* short match found: let's check for a longer one */
mLength = ZSTD_count(ip+4, matchs0+4, iend) + 4;
offset = (U32)(ip - matchs0);

/* check long match at +1 position */
if (idxl1 > prefixLowestIndex) {
if (MEM_read64(matchl1) == MEM_read64(ip1)) {
size_t const llen = ZSTD_count(ip1+8, matchl1+8, iend) + 8;
if (llen > mLength) {
ip = ip1;
mLength = llen;
offset = (U32)(ip-matchl1);
while (((ip>anchor) & (matchl1>prefixLowest)) && (ip[-1] == matchl1[-1])) { ip--; matchl1--; mLength++; } /* catch up */
goto _match_found;
} }
if ((idxl1 > prefixLowestIndex) && (MEM_read64(matchl1) == MEM_read64(ip1))) {
size_t const l1len = ZSTD_count(ip1+8, matchl1+8, iend) + 8;
if (l1len > mLength) {
/* use the long match instead */
ip = ip1;
mLength = l1len;
offset = (U32)(ip-matchl1);
matchs0 = matchl1;
}
}

/* validate short match previously found */
offset = (U32)(ip - matchs0);
while (((ip>anchor) & (matchs0>prefixLowest)) && (ip[-1] == matchs0[-1])) { ip--; matchs0--; mLength++; } /* catch up */
while (((ip>anchor) & (matchs0>prefixLowest)) && (ip[-1] == matchs0[-1])) { ip--; matchs0--; mLength++; } /* complete backward */

/* fall-through */

Expand Down

0 comments on commit 47d4f56

Please sign in to comment.