From 0068be94d82ce75bad8faa588f78d66180893f19 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Mon, 15 Feb 2016 18:42:13 +0100 Subject: [PATCH] Faster literals cost evaluation (suggested by @inikep) --- lib/zstd_opt.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/zstd_opt.h b/lib/zstd_opt.h index 6d898400..ec9a2a15 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);