]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
changed macro LOADCPARAMS by static function ZSTD_cLevelToCParams()
authorYann Collet <cyan@fb.com>
Fri, 12 May 2017 22:59:48 +0000 (15:59 -0700)
committerYann Collet <cyan@fb.com>
Fri, 12 May 2017 23:01:15 +0000 (16:01 -0700)
for improved compiler checks.
Also : ensure most parameters can receive value "0"
to mean "do not change".

doc/zstd_manual.html
lib/compress/zstd_compress.c
lib/zstd.h

index 68efb6cc8038eadb02921071e314e64dab58b57c..8c74bcff022d91c128fe27afc859a57ba8a34b76 100644 (file)
@@ -479,31 +479,37 @@ size_t ZSTD_estimateDDictSize(size_t dictSize);
                               * Special: value 0 means "do not change cLevel". */
     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.
-                              * 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>
                               * 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,         </b>/* Size of the full-search table, as a power of 2.<b>
                               * 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,        </b>/* Number of search attempts, as a power of 2.<b>
                               * 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>
                               * 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,     </b>/* Only useful for strategies >= btopt.<b>
                               * 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>
                               * 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,       </b>/* Maximum allowed back-reference distance.<b>
                               * Can be set to a more precise value than windowLog.
index e17521565ac69ed6836d75196e0c00981b1b317d..754bb8b082d93f53346e03f388035a3ea8b1bbfd 100644 (file)
@@ -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 ((val<min) | (val>max)) 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 ((val<min) | (val>max)) 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);
index 587f9f5212d8f927113342fda88e5bb1dc59649c..c1ae9da5465530fea8c9af06f1b5c5c9476bbb7a 100644 (file)
@@ -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.