Add ZSTD_set{C,F,}Params() helper functions
* Add ZSTD_setFParams() and ZSTD_setParams() * Modify ZSTD_setCParams() to use ZSTD_setParameter() to avoid a second path setting parameters * Add unit tests * Update documentation to suggest using them to replace deprecated functions Fixes #3396.
This commit is contained in:
committed by
Nick Terrell
parent
6313a58e45
commit
07a2a33135
@@ -1178,16 +1178,39 @@ size_t ZSTD_CCtx_setParametersUsingCCtxParams(
|
||||
|
||||
size_t ZSTD_CCtx_setCParams(ZSTD_CCtx* cctx, ZSTD_compressionParameters cparams)
|
||||
{
|
||||
ZSTD_STATIC_ASSERT(sizeof(cparams) == 7 * 4 /* all params are listed below */);
|
||||
DEBUGLOG(4, "ZSTD_CCtx_setCParams");
|
||||
assert(cctx != NULL);
|
||||
if (cctx->streamStage != zcss_init) {
|
||||
/* All parameters in @cparams are allowed to be updated during MT compression.
|
||||
* This must be signaled, so that MT compression picks up the changes */
|
||||
cctx->cParamsChanged = 1;
|
||||
}
|
||||
/* only update if parameters are valid */
|
||||
/* only update if all parameters are valid */
|
||||
FORWARD_IF_ERROR(ZSTD_checkCParams(cparams), "");
|
||||
cctx->requestedParams.cParams = cparams;
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(cctx, ZSTD_c_windowLog, cparams.windowLog), "");
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(cctx, ZSTD_c_chainLog, cparams.chainLog), "");
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(cctx, ZSTD_c_hashLog, cparams.hashLog), "");
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(cctx, ZSTD_c_searchLog, cparams.searchLog), "");
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(cctx, ZSTD_c_minMatch, cparams.minMatch), "");
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(cctx, ZSTD_c_targetLength, cparams.targetLength), "");
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(cctx, ZSTD_c_strategy, cparams.strategy), "");
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t ZSTD_CCtx_setFParams(ZSTD_CCtx* cctx, ZSTD_frameParameters fparams)
|
||||
{
|
||||
ZSTD_STATIC_ASSERT(sizeof(fparams) == 3 * 4 /* all params are listed below */);
|
||||
DEBUGLOG(4, "ZSTD_CCtx_setFParams");
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(cctx, ZSTD_c_contentSizeFlag, fparams.contentSizeFlag != 0), "");
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, fparams.checksumFlag != 0), "");
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setParameter(cctx, ZSTD_c_dictIDFlag, fparams.noDictIDFlag == 0), "");
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t ZSTD_CCtx_setParams(ZSTD_CCtx* cctx, ZSTD_parameters params)
|
||||
{
|
||||
DEBUGLOG(4, "ZSTD_CCtx_setParams");
|
||||
/* First check cParams, because we want to update all or none. */
|
||||
FORWARD_IF_ERROR(ZSTD_checkCParams(params.cParams), "");
|
||||
/* Next set fParams, because this could fail if the cctx isn't in init stage. */
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setFParams(cctx, params.fParams), "");
|
||||
/* Finally set cParams, which should succeed. */
|
||||
FORWARD_IF_ERROR(ZSTD_CCtx_setCParams(cctx, params.cParams), "");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user