]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
simplified ZSTD_CCtx_setParametersUsingCCtxParams()
authorYann Collet <cyan@fb.com>
Thu, 30 Nov 2017 00:13:05 +0000 (16:13 -0800)
committerYann Collet <cyan@fb.com>
Thu, 30 Nov 2017 00:13:05 +0000 (16:13 -0800)
Any ZSTD_CCtx_setParameter() shall just write the requested parameter, without further action.
Any action shall be taken at parameter application only (during init).
It makes it possible to just copy CCtxParams from external container to internal state,
and get rid of the more complex code which was trying to compensate for missing actions.

lib/compress/zstd_compress.c

index 858eaca301a12c1b68b5d6f9a3c391508d0de497..e6e0c02108107754d324ebb8a1242f561760ee79 100644 (file)
@@ -271,11 +271,11 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned v
     case ZSTD_p_forceMaxWindow :  /* Force back-references to remain < windowSize,
                                    * even when referencing into Dictionary content
                                    * default : 0 when using a CDict, 1 when using a Prefix */
-        cctx->loadedDictEnd = 0;
+        cctx->loadedDictEnd = 0;  /* ? */
         return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
 
     case ZSTD_p_nbThreads:
-        if (value > 1 && cctx->staticSize) {
+        if ((value > 1) && cctx->staticSize) {
             return ERROR(parameter_unsupported);  /* MT not compatible with static alloc */
         }
         return ZSTD_CCtxParam_setParameter(&cctx->requestedParams, param, value);
@@ -465,14 +465,17 @@ size_t ZSTD_CCtxParam_setParameter(
  * The multithreading parameters jobSize and overlapSizeLog are set only if
  * nbThreads > 1.
  *
- * Pledged srcSize is treated as unknown.
+ * pledgedSrcSize is considered unknown
  */
 size_t ZSTD_CCtx_setParametersUsingCCtxParams(
-        ZSTD_CCtx* cctx, const ZSTD_CCtx_params* params)
+        ZSTD_CCtx* const cctx, const ZSTD_CCtx_params* const params)
 {
     if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
     if (cctx->cdict) return ERROR(stage_wrong);
 
+#if 1
+    cctx->requestedParams = *params;
+#else
     /* Assume the compression and frame parameters are validated */
     cctx->requestedParams.cParams = params->cParams;
     cctx->requestedParams.fParams = params->fParams;
@@ -492,6 +495,7 @@ size_t ZSTD_CCtx_setParametersUsingCCtxParams(
 
     /* Copy long distance matching parameters */
     cctx->requestedParams.ldmParams = params->ldmParams;
+#endif
 
     /* customMem is used only for create/free params and can be ignored */
     return 0;
@@ -2858,6 +2862,7 @@ size_t ZSTD_compress_generic (ZSTD_CCtx* cctx,
                 if (cctx->mtctx == NULL) return ERROR(memory_allocation);
             }
             DEBUGLOG(4, "call ZSTDMT_initCStream_internal as nbThreads=%u", params.nbThreads);
+            DEBUGLOG(2, "params.windowLog = %u", params.cParams.windowLog);
             CHECK_F( ZSTDMT_initCStream_internal(
                         cctx->mtctx,
                         prefixDict.dict, prefixDict.dictSize, ZSTD_dm_rawContent,