mirror of
https://github.com/facebook/zstd.git
synced 2025-10-10 00:03:36 -04:00
implement suggestions
This commit is contained in:
parent
c26f348dc8
commit
df714ddb0f
@ -1264,7 +1264,7 @@ unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxS
|
|||||||
size_t maxBits, hSize, newSize;
|
size_t maxBits, hSize, newSize;
|
||||||
const unsigned symbolCardinality = HUF_cardinality(count, maxSymbolValue);
|
const unsigned symbolCardinality = HUF_cardinality(count, maxSymbolValue);
|
||||||
const unsigned minTableLog = HUF_minTableLog(symbolCardinality);
|
const unsigned minTableLog = HUF_minTableLog(symbolCardinality);
|
||||||
size_t optSize = ((size_t) ~0);
|
size_t optSize = ((size_t) ~0) - 1;
|
||||||
unsigned optLogGuess;
|
unsigned optLogGuess;
|
||||||
|
|
||||||
if (wkspSize < sizeof(HUF_buildCTable_wksp_tables)) return optLog; /** Assert workspace is large enough **/
|
if (wkspSize < sizeof(HUF_buildCTable_wksp_tables)) return optLog; /** Assert workspace is large enough **/
|
||||||
@ -1275,19 +1275,24 @@ unsigned HUF_optimalTableLog(unsigned maxTableLog, size_t srcSize, unsigned maxS
|
|||||||
|
|
||||||
if (ERR_isError(maxBits)) continue;
|
if (ERR_isError(maxBits)) continue;
|
||||||
|
|
||||||
|
if (maxBits < optLogGuess && optLogGuess > minTableLog) break;
|
||||||
|
|
||||||
hSize = HUF_writeCTable_wksp(dst, dstSize, table, maxSymbolValue, (U32)maxBits, workSpace, wkspSize);
|
hSize = HUF_writeCTable_wksp(dst, dstSize, table, maxSymbolValue, (U32)maxBits, workSpace, wkspSize);
|
||||||
|
|
||||||
if (ERR_isError(hSize)) continue;
|
if (ERR_isError(hSize)) continue;
|
||||||
|
|
||||||
newSize = HUF_estimateCompressedSize(table, count, maxSymbolValue) + hSize;
|
newSize = HUF_estimateCompressedSize(table, count, maxSymbolValue) + hSize;
|
||||||
|
|
||||||
if (newSize > optSize) {
|
if (newSize > optSize + 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newSize < optSize) {
|
||||||
optSize = newSize;
|
optSize = newSize;
|
||||||
optLog = optLogGuess;
|
optLog = optLogGuess;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
assert(optLog <= HUF_TABLELOG_MAX);
|
assert(optLog <= HUF_TABLELOG_MAX);
|
||||||
return optLog;
|
return optLog;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user