]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
minor update of literal cost function 1154/head
authorYann Collet <cyan@fb.com>
Tue, 29 May 2018 22:29:55 +0000 (15:29 -0700)
committerYann Collet <cyan@fb.com>
Tue, 29 May 2018 22:34:50 +0000 (15:34 -0700)
just assert() there is no negative cost evaluation for literals

lib/compress/zstd_opt.c

index de745b6e69a227396c7c54e2b73b071b6de07523..46a5395ac169f4df84b8e0a944239fa1a1e1d466 100644 (file)
@@ -189,12 +189,11 @@ 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, u;
-        for (u=0, price=0; u < litLength; u++) {
-            U32 const litWeight = WEIGHT(optPtr->litFreq[literals[u]], optLevel);
-            U32 litCost = optPtr->litSumBasePrice - litWeight;
-            //if (litCost < BITCOST_MULTIPLIER) litCost = BITCOST_MULTIPLIER;   /* minimum 1 bit per symbol (huffman) */
-            price += litCost;
+    {   U32 price = litLength * optPtr->litSumBasePrice;
+        U32 u;
+        for (u=0; u < litLength; u++) {
+            assert(WEIGHT(optPtr->litFreq[literals[u]], optLevel) <= optPtr->litSumBasePrice);   /* literal cost should never be negative */
+            price -= WEIGHT(optPtr->litFreq[literals[u]], optLevel);
         }
         return price;
     }