From: Danielle Rozenblit Date: Tue, 3 Jan 2023 15:20:21 +0000 (-0800) Subject: implement suggestions X-Git-Tag: v1.5.4^2~66^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df714ddb0f2dc076dc841d10c8b72f66ef5af937;p=thirdparty%2Fzstd.git implement suggestions --- diff --git a/lib/compress/huf_compress.c b/lib/compress/huf_compress.c index d7755e0f2..9a4cde6f2 100644 --- a/lib/compress/huf_compress.c +++ b/lib/compress/huf_compress.c @@ -1264,7 +1264,7 @@ unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxS size_t maxBits, hSize, newSize; const unsigned symbolCardinality = HUF_cardinality(count, maxSymbolValue); const unsigned minTableLog = HUF_minTableLog(symbolCardinality); - size_t optSize = ((size_t) ~0); + size_t optSize = ((size_t) ~0) - 1; unsigned optLogGuess; if (wkspSize < sizeof(HUF_buildCTable_wksp_tables)) return optLog; /** Assert workspace is large enough **/ @@ -1275,17 +1275,22 @@ unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxS if (ERR_isError(maxBits)) continue; + if (maxBits < optLogGuess && optLogGuess > minTableLog) break; + hSize = HUF_writeCTable_wksp(dst, dstSize, table, maxSymbolValue, (U32)maxBits, workSpace, wkspSize); if (ERR_isError(hSize)) continue; newSize = HUF_estimateCompressedSize(table, count, maxSymbolValue) + hSize; - if (newSize > optSize) { + if (newSize > optSize + 1) { break; } - optSize = newSize; - optLog = optLogGuess; + + if (newSize < optSize) { + optSize = newSize; + optLog = optLogGuess; + } } } assert(optLog <= HUF_TABLELOG_MAX);