From: Yann Collet Date: Sun, 4 Feb 2024 01:26:47 +0000 (-0800) Subject: minor optimization, mostly for clarity X-Git-Tag: v1.5.6^2~70^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8168a451e58261baf9a53b0c1bcfdaff2ba0480d;p=thirdparty%2Fzstd.git minor optimization, mostly for clarity --- diff --git a/lib/compress/zstd_opt.c b/lib/compress/zstd_opt.c index 2c4af2f06..bbf367b24 100644 --- a/lib/compress/zstd_opt.c +++ b/lib/compress/zstd_opt.c @@ -1181,7 +1181,6 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms, } last_pos = pos-1; opt[pos].price = ZSTD_MAX_PRICE; - opt[pos+1].price = ZSTD_MAX_PRICE; } } @@ -1202,19 +1201,17 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms, DEBUGLOG(7, "cPos:%zi==rPos:%u : better price (%.2f<=%.2f) using literal (ll==%u) (hist:%u,%u,%u)", inr-istart, cur, ZSTD_fCost(price), ZSTD_fCost(opt[cur].price), litlen, opt[cur-1].rep[0], opt[cur-1].rep[1], opt[cur-1].rep[2]); - opt[cur].mlen = opt[cur-1].mlen; - opt[cur].off = opt[cur-1].off; + opt[cur] = opt[cur-1]; opt[cur].litlen = litlen; opt[cur].price = price; - ZSTD_memcpy(opt[cur].rep, opt[cur - 1].rep, sizeof(repcodes_t)); if ((optLevel == 2) /* additional check only for high modes */ && (prevMatch.litlen == 0) /* interrupt a match */ - && (LL_INCPRICE(1) < 0) ) /* ll1 is cheaper than ll0 */ - { + && (LL_INCPRICE(1) < 0) /* ll1 is cheaper than ll0 */ + ) { /* check next position, in case it would be cheaper */ int with1literal = prevMatch.price + LIT_PRICE(ip+cur) + LL_INCPRICE(1); int withMoreLiterals = price + LIT_PRICE(ip+cur) + LL_INCPRICE(litlen+1); - DEBUGLOG(7, "But at next rPos %u : match+1lit %.2f vs %ulits %.2f", + DEBUGLOG(7, "then at next rPos %u : match+1lit %.2f vs %ulits %.2f", cur+1, ZSTD_fCost(with1literal), litlen+1, ZSTD_fCost(withMoreLiterals)); if ( (with1literal < withMoreLiterals) && (with1literal < opt[cur+1].price) ) { @@ -1230,13 +1227,6 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms, opt[cur+1].litlen = 1; opt[cur+1].price = with1literal; if (last_pos < cur+1) last_pos = cur+1; -#if 0 - /* but, for following byte, get back to literal run */ - opt[cur+2] = opt[cur]; - opt[cur+2].litlen += 2; - opt[cur+2].price += LIT_PRICE(ip+cur) + LIT_PRICE(ip+cur+1) + LL_INCPRICE(litlen+1) + LL_INCPRICE(litlen+2); - if (last_pos < cur+2) last_pos = cur+2; -#endif } } } else { @@ -1325,7 +1315,6 @@ ZSTD_compressBlock_opt_generic(ZSTD_matchState_t* ms, } } } } opt[last_pos+1].price = ZSTD_MAX_PRICE; - opt[last_pos+2].price = ZSTD_MAX_PRICE; } /* for (cur = 1; cur <= last_pos; cur++) */ lastStretch = opt[last_pos];