]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Faster literals cost evaluation (suggested by @inikep)
authorYann Collet <yann.collet.73@gmail.com>
Mon, 15 Feb 2016 17:42:13 +0000 (18:42 +0100)
committerYann Collet <yann.collet.73@gmail.com>
Mon, 15 Feb 2016 17:42:13 +0000 (18:42 +0100)
lib/zstd_opt.h

index 6d898400cf831ba53cb20e3ffe6296ad13339d4a..ec9a2a158ba64283447e6464e2849691f0f5e2ba 100644 (file)
@@ -79,8 +79,9 @@ FORCE_INLINE U32 ZSTD_getLiteralPriceReal(seqStore_t* seqStorePtr, U32 litLength
     if (!litLength) return 1;   /* special case */
 
     /* literals */
-    for (u=0, price=0; u < litLength; u++)
-        price += ZSTD_highbit(seqStorePtr->litSum) - ZSTD_highbit(seqStorePtr->litFreq[literals[u]]);
+    price = litLength * ZSTD_highbit(seqStorePtr->litSum);
+    for (u=0; u < litLength; u++)
+        price -= ZSTD_highbit(seqStorePtr->litFreq[literals[u]]);
 
     /* literal Length */
     price += ((litLength >= MaxLL)*8) + ((litLength >= 255+MaxLL)*16) + ((litLength>=(1<<15))*8);