diff --git a/doc/zstd_manual.html b/doc/zstd_manual.html
index 68efb6cc..8c74bcff 100644
--- a/doc/zstd_manual.html
+++ b/doc/zstd_manual.html
@@ -479,31 +479,37 @@ size_t ZSTD_estimateDDictSize(size_t dictSize);
* Special: value 0 means "do not change cLevel". */
ZSTD_p_windowLog, /* Maximum allowed back-reference distance, expressed as power of 2.
* 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.
* Resulting table size is (1 << (hashLog+2)).
* Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
* 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.
* Resulting table size is (1 << (chainLog+2)).
* 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.
* 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).
* Larger values make faster compression and decompression, but decrease ratio.
* 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 > 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.
* 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.
* Cast selected strategy as unsigned for ZSTD_CCtx_setParameter() compatibility.
* 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
ZSTD_p_windowSize, /* Maximum allowed back-reference distance.
* Can be set to a more precise value than windowLog.
diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c
index e1752156..754bb8b0 100644
--- a/lib/compress/zstd_compress.c
+++ b/lib/compress/zstd_compress.c
@@ -202,15 +202,23 @@ 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)
{
# define CLAMPCHECK(val,min,max) { if ((valmax)) return ERROR(compressionParameter_unsupported); }
-# define LOADCPARAMS(cParams) \
- if (cctx->compressionLevel!=0) { \
- cParams = ZSTD_getCParams( \
- cctx->compressionLevel, \
- cctx->frameContentSize, 0); /* dictSize unknown at this stage */ \
- cctx->compressionLevel = 0; \
+# define LOADCPARAMS(cctx) \
+ if (cctx->compressionLevel!=0) { \
+ cctx->params.cParams = ZSTD_getCParams( cctx->compressionLevel, \
+ cctx->frameContentSize, 0); \
+ cctx->compressionLevel = 0; \
}
@@ -223,44 +231,50 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned v
return 0;
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);
- LOADCPARAMS(cctx->params.cParams);
+ ZSTD_cLevelToCParams(cctx);
cctx->params.cParams.windowLog = value;
return 0;
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);
- LOADCPARAMS(cctx->params.cParams);
+ ZSTD_cLevelToCParams(cctx);
cctx->params.cParams.hashLog = value;
return 0;
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);
- LOADCPARAMS(cctx->params.cParams);
+ ZSTD_cLevelToCParams(cctx);
cctx->params.cParams.chainLog = value;
return 0;
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);
- LOADCPARAMS(cctx->params.cParams);
+ ZSTD_cLevelToCParams(cctx);
cctx->params.cParams.searchLog = value;
return 0;
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);
- LOADCPARAMS(cctx->params.cParams);
+ ZSTD_cLevelToCParams(cctx);
cctx->params.cParams.searchLength = value;
return 0;
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);
- LOADCPARAMS(cctx->params.cParams);
+ ZSTD_cLevelToCParams(cctx);
cctx->params.cParams.targetLength = value;
return 0;
case ZSTD_p_compressionStrategy :
if (value > (unsigned)ZSTD_btultra) return ERROR(compressionParameter_unsupported);
- LOADCPARAMS(cctx->params.cParams);
+ ZSTD_cLevelToCParams(cctx);
cctx->params.cParams.strategy = (ZSTD_strategy)value;
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 */
size_t ZSTD_checkCParams(ZSTD_compressionParameters cParams)
{
-# define CLAMPCHECK(val,min,max) { if ((valmax)) return ERROR(compressionParameter_unsupported); }
CLAMPCHECK(cParams.windowLog, ZSTD_WINDOWLOG_MIN, ZSTD_WINDOWLOG_MAX);
CLAMPCHECK(cParams.chainLog, ZSTD_CHAINLOG_MIN, ZSTD_CHAINLOG_MAX);
CLAMPCHECK(cParams.hashLog, ZSTD_HASHLOG_MIN, ZSTD_HASHLOG_MAX);
diff --git a/lib/zstd.h b/lib/zstd.h
index 587f9f52..c1ae9da5 100644
--- a/lib/zstd.h
+++ b/lib/zstd.h
@@ -593,31 +593,37 @@ typedef enum {
* Special: value 0 means "do not change cLevel". */
ZSTD_p_windowLog, /* Maximum allowed back-reference distance, expressed as power of 2.
* 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.
* Resulting table size is (1 << (hashLog+2)).
* Must be clamped between ZSTD_HASHLOG_MIN and ZSTD_HASHLOG_MAX.
* 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.
* Resulting table size is (1 << (chainLog+2)).
* 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.
* 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).
* Larger values make faster compression and decompression, but decrease ratio.
* 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 > 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.
* 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.
* Cast selected strategy as unsigned for ZSTD_CCtx_setParameter() compatibility.
* 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
ZSTD_p_windowSize, /* Maximum allowed back-reference distance.
* Can be set to a more precise value than windowLog.