enforce a minimum price of 1 bit per literal in the optimal parser

This commit is contained in:
Yann Collet 2022-01-07 13:51:28 -08:00
parent 5f2c3d9720
commit 9e1b4828e5

View File

@ -255,11 +255,13 @@ static U32 ZSTD_rawLiteralsCost(const BYTE* const literals, U32 const litLength,
return (litLength*6) * BITCOST_MULTIPLIER; /* 6 bit per literal - no statistic used */
/* dynamic statistics */
{ U32 price = litLength * optPtr->litSumBasePrice;
{ U32 price = 0;
U32 u;
for (u=0; u < litLength; u++) {
U32 litPrice = optPtr->litSumBasePrice - WEIGHT(optPtr->litFreq[literals[u]], optLevel);
assert(WEIGHT(optPtr->litFreq[literals[u]], optLevel) <= optPtr->litSumBasePrice); /* literal cost should never be negative */
price -= WEIGHT(optPtr->litFreq[literals[u]], optLevel);
if (litPrice < BITCOST_MULTIPLIER) litPrice = BITCOST_MULTIPLIER;
price += litPrice;
}
return price;
}