From: Yann Collet Date: Thu, 17 Oct 2024 16:36:56 +0000 (-0700) Subject: rewrite code in the manner suggested by @terrelln X-Git-Tag: v1.5.7^2~73^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47d4f5662df83c1a84476ab6c6f7fcb1d415f4f1;p=thirdparty%2Fzstd.git rewrite code in the manner suggested by @terrelln --- diff --git a/lib/compress/zstd_double_fast.c b/lib/compress/zstd_double_fast.c index 72b541ea6..50d698b37 100644 --- a/lib/compress/zstd_double_fast.c +++ b/lib/compress/zstd_double_fast.c @@ -254,23 +254,21 @@ _search_next_long: /* 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 */