minor optimization, mostly for clarity

This commit is contained in:
Yann Collet
2024-02-03 17:26:47 -08:00
parent d31018e223
commit 8168a451e5
+4 -15
View File
@@ -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];