changed macro LOADCPARAMS by static function ZSTD_cLevelToCParams()
for improved compiler checks. Also : ensure most parameters can receive value "0" to mean "do not change".
This commit is contained in:
+13
-7
@@ -479,31 +479,37 @@ size_t ZSTD_estimateDDictSize(size_t dictSize);
|
|||||||
* Special: value 0 means "do not change cLevel". */
|
* Special: value 0 means "do not change cLevel". */
|
||||||
ZSTD_p_windowLog, </b>/* Maximum allowed back-reference distance, expressed as power of 2.<b>
|
ZSTD_p_windowLog, </b>/* Maximum allowed back-reference distance, expressed as power of 2.<b>
|
||||||
* Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
|
* Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
|
||||||
* default value : set through compressionLevel */
|
* default value : set through compressionLevel.
|
||||||
|
* Special: value 0 means "do not change windowLog". */
|
||||||
ZSTD_p_hashLog, </b>/* Size of the probe table, as a power of 2.<b>
|
ZSTD_p_hashLog, </b>/* Size of the probe table, as a power of 2.<b>
|
||||||
* Resulting table size is (1 << (hashLog+2)).
|
* Resulting table size is (1 << (hashLog+2)).
|
||||||
* Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
|
* Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
|
||||||
* Larger tables improve compression ratio of strategies <= dFast,
|
* Larger tables improve compression ratio of strategies <= dFast,
|
||||||
* and improve speed of strategies > dFast */
|
* and improve speed of strategies > dFast.
|
||||||
|
* Special: value 0 means "do not change hashLog". */
|
||||||
ZSTD_p_chainLog, </b>/* Size of the full-search table, as a power of 2.<b>
|
ZSTD_p_chainLog, </b>/* Size of the full-search table, as a power of 2.<b>
|
||||||
* Resulting table size is (1 << (chainLog+2)).
|
* Resulting table size is (1 << (chainLog+2)).
|
||||||
* Larger tables result in better and slower compression.
|
* Larger tables result in better and slower compression.
|
||||||
* This parameter is useless when using "fast" strategy */
|
* This parameter is useless when using "fast" strategy.
|
||||||
|
* Special: value 0 means "do not change chainLog". */
|
||||||
ZSTD_p_searchLog, </b>/* Number of search attempts, as a power of 2.<b>
|
ZSTD_p_searchLog, </b>/* Number of search attempts, as a power of 2.<b>
|
||||||
* More attempts result in better and slower compression.
|
* More attempts result in better and slower compression.
|
||||||
* This parameter is useless when using "fast" and "dFast" strategies */
|
* This parameter is useless when using "fast" and "dFast" strategies.
|
||||||
|
* Special: value 0 means "do not change searchLog". */
|
||||||
ZSTD_p_minMatchLength, </b>/* Minimum match size (except for repeat-matches, which limit is hard-coded).<b>
|
ZSTD_p_minMatchLength, </b>/* Minimum match size (except for repeat-matches, which limit is hard-coded).<b>
|
||||||
* Larger values make faster compression and decompression, but decrease ratio.
|
* Larger values make faster compression and decompression, but decrease ratio.
|
||||||
* Must be clamped between ZSTD_SEARCHLENGTH_MIN and ZSTD_SEARCHLENGTH_MAX.
|
* Must be clamped between ZSTD_SEARCHLENGTH_MIN and ZSTD_SEARCHLENGTH_MAX.
|
||||||
* Note that currently, for all strategies < btopt, effective minimum is 4.
|
* Note that currently, for all strategies < btopt, effective minimum is 4.
|
||||||
* Note that currently, for all strategies > fast, effective maximum is 6. */
|
* Note that currently, for all strategies > fast, effective maximum is 6.
|
||||||
|
* Special: value 0 means "do not change minMatchLength". */
|
||||||
ZSTD_p_targetLength, </b>/* Only useful for strategies >= btopt.<b>
|
ZSTD_p_targetLength, </b>/* Only useful for strategies >= btopt.<b>
|
||||||
* Length of Match considered "good enough" to stop search.
|
* Length of Match considered "good enough" to stop search.
|
||||||
* Larger values make compression stronger and slower. */
|
* Larger values make compression stronger and slower.
|
||||||
|
* Special: value 0 means "do not change targetLength". */
|
||||||
ZSTD_p_compressionStrategy, </b>/* See ZSTD_strategy enum definition.<b>
|
ZSTD_p_compressionStrategy, </b>/* See ZSTD_strategy enum definition.<b>
|
||||||
* Cast selected strategy as unsigned for ZSTD_CCtx_setParameter() compatibility.
|
* Cast selected strategy as unsigned for ZSTD_CCtx_setParameter() compatibility.
|
||||||
* The higher the value of selected strategy, the more complex it is,
|
* The higher the value of selected strategy, the more complex it is,
|
||||||
* resulting in stronger and slower compression */
|
* resulting in stronger and slower compression. */
|
||||||
#if 0
|
#if 0
|
||||||
ZSTD_p_windowSize, </b>/* Maximum allowed back-reference distance.<b>
|
ZSTD_p_windowSize, </b>/* Maximum allowed back-reference distance.<b>
|
||||||
* Can be set to a more precise value than windowLog.
|
* Can be set to a more precise value than windowLog.
|
||||||
|
|||||||
@@ -202,14 +202,22 @@ size_t ZSTD_setCCtxParameter(ZSTD_CCtx* cctx, ZSTD_CCtxParameter param, unsigned
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void ZSTD_cLevelToCParams(ZSTD_CCtx* cctx)
|
||||||
|
{
|
||||||
|
if (cctx->compressionLevel==0) return;
|
||||||
|
cctx->params.cParams = ZSTD_getCParams(cctx->compressionLevel,
|
||||||
|
cctx->frameContentSize, 0);
|
||||||
|
cctx->compressionLevel = 0;
|
||||||
|
}
|
||||||
|
|
||||||
size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned value)
|
size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned value)
|
||||||
{
|
{
|
||||||
# define CLAMPCHECK(val,min,max) { if ((val<min) | (val>max)) return ERROR(compressionParameter_unsupported); }
|
# define CLAMPCHECK(val,min,max) { if ((val<min) | (val>max)) return ERROR(compressionParameter_unsupported); }
|
||||||
# define LOADCPARAMS(cParams) \
|
# define LOADCPARAMS(cctx) \
|
||||||
if (cctx->compressionLevel!=0) { \
|
if (cctx->compressionLevel!=0) { \
|
||||||
cParams = ZSTD_getCParams( \
|
cctx->params.cParams = ZSTD_getCParams( cctx->compressionLevel, \
|
||||||
cctx->compressionLevel, \
|
cctx->frameContentSize, 0); \
|
||||||
cctx->frameContentSize, 0); /* dictSize unknown at this stage */ \
|
|
||||||
cctx->compressionLevel = 0; \
|
cctx->compressionLevel = 0; \
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -223,44 +231,50 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned v
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case ZSTD_p_windowLog :
|
case ZSTD_p_windowLog :
|
||||||
|
if (value == 0) return 0; /* special value : 0 means "don't change anything" */
|
||||||
CLAMPCHECK(value, ZSTD_WINDOWLOG_MIN, ZSTD_WINDOWLOG_MAX);
|
CLAMPCHECK(value, ZSTD_WINDOWLOG_MIN, ZSTD_WINDOWLOG_MAX);
|
||||||
LOADCPARAMS(cctx->params.cParams);
|
ZSTD_cLevelToCParams(cctx);
|
||||||
cctx->params.cParams.windowLog = value;
|
cctx->params.cParams.windowLog = value;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case ZSTD_p_hashLog :
|
case ZSTD_p_hashLog :
|
||||||
|
if (value == 0) return 0; /* special value : 0 means "don't change anything" */
|
||||||
CLAMPCHECK(value, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX);
|
CLAMPCHECK(value, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX);
|
||||||
LOADCPARAMS(cctx->params.cParams);
|
ZSTD_cLevelToCParams(cctx);
|
||||||
cctx->params.cParams.hashLog = value;
|
cctx->params.cParams.hashLog = value;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case ZSTD_p_chainLog :
|
case ZSTD_p_chainLog :
|
||||||
|
if (value == 0) return 0; /* special value : 0 means "don't change anything" */
|
||||||
CLAMPCHECK(value, ZSTD_CHAINLOG_MIN, ZSTD_CHAINLOG_MAX);
|
CLAMPCHECK(value, ZSTD_CHAINLOG_MIN, ZSTD_CHAINLOG_MAX);
|
||||||
LOADCPARAMS(cctx->params.cParams);
|
ZSTD_cLevelToCParams(cctx);
|
||||||
cctx->params.cParams.chainLog = value;
|
cctx->params.cParams.chainLog = value;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case ZSTD_p_searchLog :
|
case ZSTD_p_searchLog :
|
||||||
|
if (value == 0) return 0; /* special value : 0 means "don't change anything" */
|
||||||
CLAMPCHECK(value, ZSTD_SEARCHLOG_MIN, ZSTD_SEARCHLOG_MAX);
|
CLAMPCHECK(value, ZSTD_SEARCHLOG_MIN, ZSTD_SEARCHLOG_MAX);
|
||||||
LOADCPARAMS(cctx->params.cParams);
|
ZSTD_cLevelToCParams(cctx);
|
||||||
cctx->params.cParams.searchLog = value;
|
cctx->params.cParams.searchLog = value;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case ZSTD_p_minMatchLength :
|
case ZSTD_p_minMatchLength :
|
||||||
|
if (value == 0) return 0; /* special value : 0 means "don't change anything" */
|
||||||
CLAMPCHECK(value, ZSTD_SEARCHLENGTH_MIN, ZSTD_SEARCHLENGTH_MAX);
|
CLAMPCHECK(value, ZSTD_SEARCHLENGTH_MIN, ZSTD_SEARCHLENGTH_MAX);
|
||||||
LOADCPARAMS(cctx->params.cParams);
|
ZSTD_cLevelToCParams(cctx);
|
||||||
cctx->params.cParams.searchLength = value;
|
cctx->params.cParams.searchLength = value;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case ZSTD_p_targetLength :
|
case ZSTD_p_targetLength :
|
||||||
|
if (value == 0) return 0; /* special value : 0 means "don't change anything" */
|
||||||
CLAMPCHECK(value, ZSTD_TARGETLENGTH_MIN, ZSTD_TARGETLENGTH_MAX);
|
CLAMPCHECK(value, ZSTD_TARGETLENGTH_MIN, ZSTD_TARGETLENGTH_MAX);
|
||||||
LOADCPARAMS(cctx->params.cParams);
|
ZSTD_cLevelToCParams(cctx);
|
||||||
cctx->params.cParams.targetLength = value;
|
cctx->params.cParams.targetLength = value;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case ZSTD_p_compressionStrategy :
|
case ZSTD_p_compressionStrategy :
|
||||||
if (value > (unsigned)ZSTD_btultra) return ERROR(compressionParameter_unsupported);
|
if (value > (unsigned)ZSTD_btultra) return ERROR(compressionParameter_unsupported);
|
||||||
LOADCPARAMS(cctx->params.cParams);
|
ZSTD_cLevelToCParams(cctx);
|
||||||
cctx->params.cParams.strategy = (ZSTD_strategy)value;
|
cctx->params.cParams.strategy = (ZSTD_strategy)value;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
@@ -325,7 +339,6 @@ ZSTDLIB_API size_t ZSTD_CCtx_refCDict(ZSTD_CCtx* cctx, const ZSTD_CDict* cdict)
|
|||||||
@return : 0, or an error code if one value is beyond authorized range */
|
@return : 0, or an error code if one value is beyond authorized range */
|
||||||
size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams)
|
size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams)
|
||||||
{
|
{
|
||||||
# define CLAMPCHECK(val,min,max) { if ((val<min) | (val>max)) return ERROR(compressionParameter_unsupported); }
|
|
||||||
CLAMPCHECK(cParams.windowLog, ZSTD_WINDOWLOG_MIN, ZSTD_WINDOWLOG_MAX);
|
CLAMPCHECK(cParams.windowLog, ZSTD_WINDOWLOG_MIN, ZSTD_WINDOWLOG_MAX);
|
||||||
CLAMPCHECK(cParams.chainLog, ZSTD_CHAINLOG_MIN, ZSTD_CHAINLOG_MAX);
|
CLAMPCHECK(cParams.chainLog, ZSTD_CHAINLOG_MIN, ZSTD_CHAINLOG_MAX);
|
||||||
CLAMPCHECK(cParams.hashLog, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX);
|
CLAMPCHECK(cParams.hashLog, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX);
|
||||||
|
|||||||
+13
-7
@@ -593,31 +593,37 @@ typedef enum {
|
|||||||
* Special: value 0 means "do not change cLevel". */
|
* Special: value 0 means "do not change cLevel". */
|
||||||
ZSTD_p_windowLog, /* Maximum allowed back-reference distance, expressed as power of 2.
|
ZSTD_p_windowLog, /* Maximum allowed back-reference distance, expressed as power of 2.
|
||||||
* Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
|
* Must be clamped between ZSTD_WINDOWLOG_MIN and ZSTD_WINDOWLOG_MAX.
|
||||||
* default value : set through compressionLevel */
|
* default value : set through compressionLevel.
|
||||||
|
* Special: value 0 means "do not change windowLog". */
|
||||||
ZSTD_p_hashLog, /* Size of the probe table, as a power of 2.
|
ZSTD_p_hashLog, /* Size of the probe table, as a power of 2.
|
||||||
* Resulting table size is (1 << (hashLog+2)).
|
* Resulting table size is (1 << (hashLog+2)).
|
||||||
* Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
|
* Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
|
||||||
* Larger tables improve compression ratio of strategies <= dFast,
|
* Larger tables improve compression ratio of strategies <= dFast,
|
||||||
* and improve speed of strategies > dFast */
|
* and improve speed of strategies > dFast.
|
||||||
|
* Special: value 0 means "do not change hashLog". */
|
||||||
ZSTD_p_chainLog, /* Size of the full-search table, as a power of 2.
|
ZSTD_p_chainLog, /* Size of the full-search table, as a power of 2.
|
||||||
* Resulting table size is (1 << (chainLog+2)).
|
* Resulting table size is (1 << (chainLog+2)).
|
||||||
* Larger tables result in better and slower compression.
|
* Larger tables result in better and slower compression.
|
||||||
* This parameter is useless when using "fast" strategy */
|
* This parameter is useless when using "fast" strategy.
|
||||||
|
* Special: value 0 means "do not change chainLog". */
|
||||||
ZSTD_p_searchLog, /* Number of search attempts, as a power of 2.
|
ZSTD_p_searchLog, /* Number of search attempts, as a power of 2.
|
||||||
* More attempts result in better and slower compression.
|
* More attempts result in better and slower compression.
|
||||||
* This parameter is useless when using "fast" and "dFast" strategies */
|
* This parameter is useless when using "fast" and "dFast" strategies.
|
||||||
|
* Special: value 0 means "do not change searchLog". */
|
||||||
ZSTD_p_minMatchLength, /* Minimum match size (except for repeat-matches, which limit is hard-coded).
|
ZSTD_p_minMatchLength, /* Minimum match size (except for repeat-matches, which limit is hard-coded).
|
||||||
* Larger values make faster compression and decompression, but decrease ratio.
|
* Larger values make faster compression and decompression, but decrease ratio.
|
||||||
* Must be clamped between ZSTD_SEARCHLENGTH_MIN and ZSTD_SEARCHLENGTH_MAX.
|
* Must be clamped between ZSTD_SEARCHLENGTH_MIN and ZSTD_SEARCHLENGTH_MAX.
|
||||||
* Note that currently, for all strategies < btopt, effective minimum is 4.
|
* Note that currently, for all strategies < btopt, effective minimum is 4.
|
||||||
* Note that currently, for all strategies > fast, effective maximum is 6. */
|
* Note that currently, for all strategies > fast, effective maximum is 6.
|
||||||
|
* Special: value 0 means "do not change minMatchLength". */
|
||||||
ZSTD_p_targetLength, /* Only useful for strategies >= btopt.
|
ZSTD_p_targetLength, /* Only useful for strategies >= btopt.
|
||||||
* Length of Match considered "good enough" to stop search.
|
* Length of Match considered "good enough" to stop search.
|
||||||
* Larger values make compression stronger and slower. */
|
* Larger values make compression stronger and slower.
|
||||||
|
* Special: value 0 means "do not change targetLength". */
|
||||||
ZSTD_p_compressionStrategy, /* See ZSTD_strategy enum definition.
|
ZSTD_p_compressionStrategy, /* See ZSTD_strategy enum definition.
|
||||||
* Cast selected strategy as unsigned for ZSTD_CCtx_setParameter() compatibility.
|
* Cast selected strategy as unsigned for ZSTD_CCtx_setParameter() compatibility.
|
||||||
* The higher the value of selected strategy, the more complex it is,
|
* The higher the value of selected strategy, the more complex it is,
|
||||||
* resulting in stronger and slower compression */
|
* resulting in stronger and slower compression. */
|
||||||
#if 0
|
#if 0
|
||||||
ZSTD_p_windowSize, /* Maximum allowed back-reference distance.
|
ZSTD_p_windowSize, /* Maximum allowed back-reference distance.
|
||||||
* Can be set to a more precise value than windowLog.
|
* Can be set to a more precise value than windowLog.
|
||||||
|
|||||||
Reference in New Issue
Block a user