]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Add function to apply cctx params
authorStella Lau <laus@fb.com>
Fri, 18 Aug 2017 20:01:55 +0000 (13:01 -0700)
committerStella Lau <laus@fb.com>
Fri, 18 Aug 2017 20:01:55 +0000 (13:01 -0700)
lib/common/zstd_internal.h
lib/compress/zstd_compress.c

index 7ea2ecc476303d514f3fb477e9e88b4c24e0aa45..fa9f0c49c0cfd5784e1e81fbe845cc96cd2702fe 100644 (file)
@@ -221,22 +221,6 @@ typedef struct seqDef_s {
     U16 matchLength;
 } seqDef;
 
-typedef struct ZSTD_CCtx_params_s {
-    ZSTD_compressionParameters cParams;
-    ZSTD_frameParameters fParams;
-
-    int compressionLevel;
-    U32 forceWindow;
-
-    /* Dictionary */
-    ZSTD_dictMode_e dictMode;
-    U32 dictContentByRef;
-
-    /* Multithreading */
-    U32 nbThreads;
-
-} ZSTD_CCtx_params;
-
 typedef struct {
     seqDef* sequencesStart;
     seqDef* sequences;
@@ -251,6 +235,24 @@ typedef struct {
     U32   repToConfirm[ZSTD_REP_NUM];
 } seqStore_t;
 
+struct ZSTD_CCtx_params_s {
+    ZSTD_compressionParameters cParams;
+    ZSTD_frameParameters fParams;
+
+    int compressionLevel;
+
+    U32 forceWindow;           /* force back-references to respect limit of 1<<wLog, even for dictionary */
+
+    /* Dictionary */
+    ZSTD_dictMode_e dictMode;   /* select restricting dictionary to "rawContent" or "fullDict" only */
+    U32 dictContentByRef;
+    U32 nbThreads;
+
+    /* Multithreading: used only to set mtctx parameters */
+    unsigned jobSize;
+    unsigned overlapSizeLog;
+};
+
 typedef struct {
     U32 off;
     U32 len;
index e47ae9a1e93ab2538e8373f3104988cd8cd9aca8..426636cfc4129028862a91b6b04a22a68e98bae4 100644 (file)
@@ -70,6 +70,7 @@ struct ZSTD_CDict_s {
     ZSTD_CCtx* refContext;
 };  /* typedef'd to ZSTD_CDict within "zstd.h" */
 
+
 struct ZSTD_CCtx_s {
     const BYTE* nextSrc;    /* next block here to continue on current prefix */
     const BYTE* base;       /* All regular indexes relative to this position */
@@ -558,21 +559,41 @@ size_t ZSTD_CCtxParam_setParameter(
         return 0;
 
     case ZSTD_p_jobSize :
-        // TODO
+        if (params->nbThreads <= 1) { return ERROR(parameter_unsupported); }
+        params->jobSize = value;
         return 0;
 
     case ZSTD_p_overlapSizeLog :
-        // TODO
+        params->overlapSizeLog = value;
         return 0;
 
     default: return ERROR(parameter_unsupported);
     }
 }
 
+// This function should probably be updated whenever ZSTD_CCtx_params is updated.
 ZSTDLIB_API size_t ZSTD_CCtx_applyCCtxParams(ZSTD_CCtx* cctx, ZSTD_CCtx_params* params)
 {
-    (void)cctx;
-    (void)params;
+    if (cctx->cdict) { return ERROR(stage_wrong); }
+
+    /* Assume the compression and frame parameters are validated */
+    cctx->requestedParams.cParams = params->cParams;
+    cctx->requestedParams.fParams = params->fParams;
+    cctx->requestedParams.compressionLevel = params->compressionLevel;
+
+    /* Assume dictionary parameters are validated */
+    cctx->requestedParams.dictMode = params->dictMode;
+    cctx->requestedParams.dictContentByRef = params->dictContentByRef;
+
+    /* Set force window explicitly since it sets cctx->loadedDictEnd */
+    CHECK_F( ZSTD_CCtx_setParameter(
+                   cctx, ZSTD_p_forceMaxWindow, params->forceWindow) );
+
+    /* Set multithreading parameters explicitly */
+    CHECK_F( ZSTD_CCtx_setParameter(cctx, ZSTD_p_nbThreads, params->nbThreads) );
+    CHECK_F( ZSTD_CCtx_setParameter(cctx, ZSTD_p_jobSize, params->jobSize) );
+    CHECK_F( ZSTD_CCtx_setParameter(
+                    cctx, ZSTD_p_overlapSizeLog, params->overlapSizeLog) );
     return 0;
 }