From: Yann Collet Date: Mon, 15 Feb 2016 17:42:13 +0000 (+0100) Subject: Faster literals cost evaluation (suggested by @inikep) X-Git-Tag: v0.5.1^2~3^2~9 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0068be94d82ce75bad8faa588f78d66180893f19;p=thirdparty%2Fzstd.git Faster literals cost evaluation (suggested by @inikep) --- diff --git a/lib/zstd_opt.h b/lib/zstd_opt.h index 6d898400c..ec9a2a158 100644 --- a/lib/zstd_opt.h +++ b/lib/zstd_opt.h @@ -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);