Remove Strategy-Dependency in Making Attachment Decision

dev
W. Felix Handte 2018-09-12 12:04:04 -07:00
parent 00c088b32d
commit 77fd17d93f
1 changed files with 18 additions and 30 deletions

View File

@ -1320,31 +1320,25 @@ static const size_t attachDictSizeCutoffs[(unsigned)ZSTD_btultra+1] = {
8 KB /* ZSTD_btultra */ 8 KB /* ZSTD_btultra */
}; };
static const ZSTD_strategy splitLogCutoffStrategy = ZSTD_btultra; static int ZSTD_shouldAttachDict(const ZSTD_CDict* cdict,
ZSTD_CCtx_params params,
static int ZSTD_shouldAttachDict(ZSTD_CCtx* cctx, U64 pledgedSrcSize)
const ZSTD_CDict* cdict,
ZSTD_CCtx_params params,
U64 pledgedSrcSize)
{ {
size_t cutoff = attachDictSizeCutoffs[cdict->matchState.cParams.strategy]; size_t cutoff = attachDictSizeCutoffs[cdict->matchState.cParams.strategy];
return ( pledgedSrcSize <= cutoff return ( pledgedSrcSize <= cutoff
|| pledgedSrcSize == ZSTD_CONTENTSIZE_UNKNOWN || pledgedSrcSize == ZSTD_CONTENTSIZE_UNKNOWN
|| params.attachDictPref == ZSTD_dictForceAttach ) || params.attachDictPref == ZSTD_dictForceAttach )
&& params.attachDictPref != ZSTD_dictForceCopy && params.attachDictPref != ZSTD_dictForceCopy
&& !params.forceWindow /* dictMatchState isn't correctly && !params.forceWindow; /* dictMatchState isn't correctly
* handled in _enforceMaxDist */ * handled in _enforceMaxDist */
&& ( (cdict->matchState.cParams.strategy <= splitLogCutoffStrategy)
|| (cdict->matchState.cParams.strategy > splitLogCutoffStrategy &&
ZSTD_equivalentCParams(cctx->appliedParams.cParams,
cdict->matchState.cParams)));
} }
static size_t ZSTD_resetCCtx_byAttachingCDict(ZSTD_CCtx* cctx, static size_t ZSTD_resetCCtx_byAttachingCDict(
const ZSTD_CDict* cdict, ZSTD_CCtx* cctx,
ZSTD_CCtx_params params, const ZSTD_CDict* cdict,
U64 pledgedSrcSize, ZSTD_CCtx_params params,
ZSTD_buffered_policy_e zbuff) U64 pledgedSrcSize,
ZSTD_buffered_policy_e zbuff)
{ {
{ {
const ZSTD_compressionParameters *cdict_cParams = &cdict->matchState.cParams; const ZSTD_compressionParameters *cdict_cParams = &cdict->matchState.cParams;
@ -1353,21 +1347,15 @@ static size_t ZSTD_resetCCtx_byAttachingCDict(ZSTD_CCtx* cctx,
/* Copy only compression parameters related to tables. */ /* Copy only compression parameters related to tables. */
params.cParams = *cdict_cParams; params.cParams = *cdict_cParams;
params.cParams.windowLog = windowLog; params.cParams.windowLog = windowLog;
if (params.cParams.strategy <= splitLogCutoffStrategy) { DEBUGLOG(4, "Overriding hashLog from %d to %d", params.cParams.hashLog, cctx->requestedParams.cParams.hashLog);
DEBUGLOG(4, "Overriding hashLog from %d to %d", params.cParams.hashLog, cctx->requestedParams.cParams.hashLog); DEBUGLOG(4, "Overriding chainLog from %d to %d", params.cParams.chainLog, cctx->requestedParams.cParams.chainLog);
DEBUGLOG(4, "Overriding chainLog from %d to %d", params.cParams.chainLog, cctx->requestedParams.cParams.chainLog); if (cctx->requestedParams.cParams.hashLog)
if (cctx->requestedParams.cParams.hashLog) params.cParams.hashLog = cctx->requestedParams.cParams.hashLog;
params.cParams.hashLog = cctx->requestedParams.cParams.hashLog; if (cctx->requestedParams.cParams.chainLog)
if (cctx->requestedParams.cParams.chainLog) params.cParams.chainLog = cctx->requestedParams.cParams.chainLog;
params.cParams.chainLog = cctx->requestedParams.cParams.chainLog;
}
ZSTD_resetCCtx_internal(cctx, params, pledgedSrcSize, ZSTD_resetCCtx_internal(cctx, params, pledgedSrcSize,
ZSTDcrp_continue, zbuff); ZSTDcrp_continue, zbuff);
assert(cctx->appliedParams.cParams.strategy == cdict_cParams->strategy); assert(cctx->appliedParams.cParams.strategy == cdict_cParams->strategy);
if (params.cParams.strategy > splitLogCutoffStrategy) {
assert(cctx->appliedParams.cParams.hashLog == cdict_cParams->hashLog);
assert(cctx->appliedParams.cParams.chainLog == cdict_cParams->chainLog);
}
} }
{ {
@ -1468,7 +1456,7 @@ static size_t ZSTD_resetCCtx_usingCDict(ZSTD_CCtx* cctx,
DEBUGLOG(4, "ZSTD_resetCCtx_usingCDict (pledgedSrcSize=%u)", (U32)pledgedSrcSize); DEBUGLOG(4, "ZSTD_resetCCtx_usingCDict (pledgedSrcSize=%u)", (U32)pledgedSrcSize);
if (ZSTD_shouldAttachDict(cctx, cdict, params, pledgedSrcSize)) { if (ZSTD_shouldAttachDict(cdict, params, pledgedSrcSize)) {
return ZSTD_resetCCtx_byAttachingCDict( return ZSTD_resetCCtx_byAttachingCDict(
cctx, cdict, params, pledgedSrcSize, zbuff); cctx, cdict, params, pledgedSrcSize, zbuff);
} else { } else {