Pull Attachment Decision into Separate Function
This commit is contained in:
@@ -1302,16 +1302,11 @@ void ZSTD_invalidateRepCodes(ZSTD_CCtx* cctx) {
|
|||||||
assert(!ZSTD_window_hasExtDict(cctx->blockState.matchState.window));
|
assert(!ZSTD_window_hasExtDict(cctx->blockState.matchState.window));
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t ZSTD_resetCCtx_usingCDict(ZSTD_CCtx* cctx,
|
/* These are the approximate sizes for each strategy past which copying the
|
||||||
const ZSTD_CDict* cdict,
|
* dictionary tables into the working context is faster than using them
|
||||||
ZSTD_CCtx_params params,
|
* in-place.
|
||||||
U64 pledgedSrcSize,
|
*/
|
||||||
ZSTD_buffered_policy_e zbuff)
|
static const size_t attachDictSizeCutoffs[(unsigned)ZSTD_btultra+1] = {
|
||||||
{
|
|
||||||
/* We have a choice between copying the dictionary context into the working
|
|
||||||
* context, or referencing the dictionary context from the working context
|
|
||||||
* in-place. We decide here which strategy to use. */
|
|
||||||
const U64 attachDictSizeCutoffs[(unsigned)ZSTD_btultra+1] = {
|
|
||||||
8 KB, /* unused */
|
8 KB, /* unused */
|
||||||
8 KB, /* ZSTD_fast */
|
8 KB, /* ZSTD_fast */
|
||||||
16 KB, /* ZSTD_dfast */
|
16 KB, /* ZSTD_dfast */
|
||||||
@@ -1322,15 +1317,34 @@ static size_t ZSTD_resetCCtx_usingCDict(ZSTD_CCtx* cctx,
|
|||||||
32 KB, /* ZSTD_btopt */
|
32 KB, /* ZSTD_btopt */
|
||||||
8 KB /* ZSTD_btultra */
|
8 KB /* ZSTD_btultra */
|
||||||
};
|
};
|
||||||
const ZSTD_compressionParameters *cdict_cParams = &cdict->matchState.cParams;
|
|
||||||
const int attachDict = ( pledgedSrcSize <= attachDictSizeCutoffs[cdict_cParams->strategy]
|
static int ZSTD_shouldAttachDict(ZSTD_CCtx* cctx,
|
||||||
|
const ZSTD_CDict* cdict,
|
||||||
|
ZSTD_CCtx_params params,
|
||||||
|
U64 pledgedSrcSize)
|
||||||
|
{
|
||||||
|
size_t cutoff = attachDictSizeCutoffs[cdict->matchState.cParams.strategy];
|
||||||
|
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 */
|
||||||
&& ZSTD_equivalentCParams(cctx->appliedParams.cParams,
|
&& ZSTD_equivalentCParams(cctx->appliedParams.cParams,
|
||||||
*cdict_cParams);
|
cdict->matchState.cParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
static size_t ZSTD_resetCCtx_usingCDict(ZSTD_CCtx* cctx,
|
||||||
|
const ZSTD_CDict* cdict,
|
||||||
|
ZSTD_CCtx_params params,
|
||||||
|
U64 pledgedSrcSize,
|
||||||
|
ZSTD_buffered_policy_e zbuff)
|
||||||
|
{
|
||||||
|
/* We have a choice between copying the dictionary context into the working
|
||||||
|
* context, or referencing the dictionary context from the working context
|
||||||
|
* in-place. We decide here which strategy to use. */
|
||||||
|
const ZSTD_compressionParameters *cdict_cParams = &cdict->matchState.cParams;
|
||||||
|
const int attachDict = ZSTD_shouldAttachDict(cctx, cdict, params, pledgedSrcSize);
|
||||||
|
|
||||||
DEBUGLOG(4, "ZSTD_resetCCtx_usingCDict (pledgedSrcSize=%u)", (U32)pledgedSrcSize);
|
DEBUGLOG(4, "ZSTD_resetCCtx_usingCDict (pledgedSrcSize=%u)", (U32)pledgedSrcSize);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user