]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Changed `ZSTD_adjustCParams()` prototype
authorYann Collet <yann.collet.73@gmail.com>
Wed, 1 Jun 2016 16:45:34 +0000 (18:45 +0200)
committerYann Collet <yann.collet.73@gmail.com>
Wed, 1 Jun 2016 16:45:34 +0000 (18:45 +0200)
`ZSTD_adjustCParams()` is now automatically invoked at the end of `ZSTD_getCParams()`

lib/common/zstd_static.h
lib/compress/zbuff_compress.c
lib/compress/zstd_compress.c
programs/bench.c
programs/zbufftest.c

index e4c992beeced39f8deccb274f8dde414138ff4f2..01aaecf6d46bde88e717135b301860bbc338f0f9 100644 (file)
@@ -127,7 +127,7 @@ ZSTDLIB_API size_t ZSTD_checkCParams(ZSTD_compressionParameters params);
 /*! ZSTD_adjustParams() :
 *   optimize params for a given `srcSize` and `dictSize`.
 *   both values are optional, select `0` if unknown. */
-ZSTDLIB_API void ZSTD_adjustCParams(ZSTD_compressionParameters* params, U64 srcSize, size_t dictSize);
+ZSTDLIB_API ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, U64 srcSize, size_t dictSize);
 
 /*! ZSTD_compress_advanced() :
 *   Same as ZSTD_compress_usingDict(), with fine-tune control of each compression parameter */
index 66deb495f6bf1b434b17341b52b1bcd37d388808..ee33df541bf64fb7285f84a4e9e974d4b40e247b 100644 (file)
@@ -182,8 +182,6 @@ size_t ZBUFF_compressInitDictionary(ZBUFF_CCtx* zbc, const void* dict, size_t di
     ZSTD_parameters params;
     memset(&params, 0, sizeof(params));
     params.cParams = ZSTD_getCParams(compressionLevel, 0, dictSize);
-    params.fParams.contentSizeFlag = 0;
-    ZSTD_adjustCParams(&params.cParams, 0, dictSize);
     return ZBUFF_compressInit_advanced(zbc, dict, dictSize, params, 0);
 }
 
index a9a2dc79d31bfb710b23a75495761d31e06e08fc..7c7349b5492e9e71e73a8fba97ae7c99498ce083 100644 (file)
@@ -202,30 +202,32 @@ size_t ZSTD_checkCParams_advanced(ZSTD_compressionParameters cParams, U64 srcSiz
 }
 
 
-/** ZSTD_adjustParams() :
-    optimize params for q given input (`srcSize` and `dictSize`).
+/** ZSTD_adjustCParams() :
+    optimize cPar for a given input (`srcSize` and `dictSize`).
     mostly downsizing to reduce memory consumption and initialization.
     Both `srcSize` and `dictSize` are optional (use 0 if unknown),
     but if both are 0, no optimization can be done.
-    Note : params is considered validated at this stage. Use ZSTD_checkParams() to ensure that. */
-void ZSTD_adjustCParams(ZSTD_compressionParameters* params, U64 srcSize, size_t dictSize)
+    Note : cPar is considered validated at this stage. Use ZSTD_checkParams() to ensure that. */
+ZSTD_compressionParameters ZSTD_adjustCParams(ZSTD_compressionParameters cPar, U64 srcSize, size_t dictSize)
 {
-    if (srcSize+dictSize == 0) return;   /* no size information available : no adjustment */
+    if (srcSize+dictSize == 0) return cPar;   /* no size information available : no adjustment */
 
     /* resize params, to use less memory when necessary */
     {   U32 const minSrcSize = (srcSize==0) ? 500 : 0;
         U64 const rSize = srcSize + dictSize + minSrcSize;
         if (rSize < ((U64)1<<ZSTD_WINDOWLOG_MAX)) {
             U32 const srcLog = ZSTD_highbit((U32)(rSize)-1) + 1;
-            if (params->windowLog > srcLog) params->windowLog = srcLog;
+            if (cPar.windowLog > srcLog) cPar.windowLog = srcLog;
     }   }
-    if (params->hashLog > params->windowLog) params->hashLog = params->windowLog;
-    {   U32 const btPlus = (params->strategy == ZSTD_btlazy2) || (params->strategy == ZSTD_btopt);
-        U32 const maxChainLog = params->windowLog+btPlus;
-        if (params->chainLog > maxChainLog) params->chainLog = maxChainLog; }   /* <= ZSTD_CHAINLOG_MAX */
+    if (cPar.hashLog > cPar.windowLog) cPar.hashLog = cPar.windowLog;
+    {   U32 const btPlus = (cPar.strategy == ZSTD_btlazy2) || (cPar.strategy == ZSTD_btopt);
+        U32 const maxChainLog = cPar.windowLog+btPlus;
+        if (cPar.chainLog > maxChainLog) cPar.chainLog = maxChainLog; }   /* <= ZSTD_CHAINLOG_MAX */
 
-    if (params->windowLog  < ZSTD_WINDOWLOG_ABSOLUTEMIN) params->windowLog = ZSTD_WINDOWLOG_ABSOLUTEMIN;  /* required for frame header */
-    if ((params->hashLog  < ZSTD_HASHLOG_MIN) && ((U32)params->strategy >= (U32)ZSTD_btlazy2)) params->hashLog = ZSTD_HASHLOG_MIN;  /* required to ensure collision resistance in bt */
+    if (cPar.windowLog < ZSTD_WINDOWLOG_ABSOLUTEMIN) cPar.windowLog = ZSTD_WINDOWLOG_ABSOLUTEMIN;  /* required for frame header */
+    if ((cPar.hashLog  < ZSTD_HASHLOG_MIN) && ( (U32)cPar.strategy >= (U32)ZSTD_btlazy2)) cPar.hashLog = ZSTD_HASHLOG_MIN;  /* required to ensure collision resistance in bt */
+
+    return cPar;
 }
 
 
@@ -2362,7 +2364,6 @@ size_t ZSTD_compressBegin_usingDict(ZSTD_CCtx* zc, const void* dict, size_t dict
     ZSTD_parameters params;
     memset(&params, 0, sizeof(params));
     params.cParams = ZSTD_getCParams(compressionLevel, 0, dictSize);
-    ZSTD_adjustCParams(&params.cParams, 0, dictSize);
     ZSTD_LOG_BLOCK("%p: ZSTD_compressBegin_usingDict compressionLevel=%d\n", zc->base, compressionLevel);
     return ZSTD_compressBegin_internal(zc, dict, dictSize, params, 0);
 }
@@ -2472,7 +2473,6 @@ size_t ZSTD_compress_usingDict(ZSTD_CCtx* ctx, void* dst, size_t dstCapacity, co
     ZSTD_LOG_BLOCK("%p: ZSTD_compress_usingDict srcSize=%d dictSize=%d compressionLevel=%d\n", ctx->base, (int)srcSize, (int)dictSize, compressionLevel);
     params.cParams =  ZSTD_getCParams(compressionLevel, srcSize, dictSize);
     params.fParams.contentSizeFlag = 1;
-    ZSTD_adjustCParams(&params.cParams, srcSize, dictSize);
     return ZSTD_compress_internal(ctx, dst, dstCapacity, src, srcSize, dict, dictSize, params);
 }
 
@@ -2625,5 +2625,6 @@ ZSTD_compressionParameters ZSTD_getCParams(int compressionLevel, U64 srcSize, si
         if (cp.chainLog > ZSTD_CHAINLOG_MAX) cp.chainLog = ZSTD_CHAINLOG_MAX;
         if (cp.hashLog > ZSTD_HASHLOG_MAX) cp.hashLog = ZSTD_HASHLOG_MAX;
     }
+    cp = ZSTD_adjustCParams(cp, srcSize, dictSize);
     return cp;
 }
index 52c64d5254efeb5c15bc03652af1dfc4cb4b7bc2..97f71162b0c871193b068840f62fc84a2cada0f0 100644 (file)
@@ -220,7 +220,6 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize,
                     {   ZSTD_parameters params;
                         params.cParams = ZSTD_getCParams(cLevel, blockSize, dictBufferSize);
                         params.fParams.contentSizeFlag = 1;
-                        ZSTD_adjustCParams(&params.cParams, blockSize, dictBufferSize);
                         {   size_t const initResult = ZSTD_compressBegin_advanced(refCtx, dictBuffer, dictBufferSize, params, blockSize);
                             if (ZSTD_isError(initResult)) break;
                     }   }
@@ -505,4 +504,3 @@ int BMK_benchFiles(const char** fileNamesTable, unsigned nbFiles,
         BMK_benchFileTable(fileNamesTable, nbFiles, dictFileName, cLevel, cLevelLast);
     return 0;
 }
-
index 1669229700da1f600646dc2de1cccfe2cbf92627..fd9269bd66e283c5a9151e8e47cd381ee2f73ae6 100644 (file)
@@ -375,12 +375,11 @@ static int fuzzerTests(U32 seed, U32 nbTests, unsigned startTest, double compres
             {   size_t const dictStart = FUZ_rand(&lseed) % (srcBufferSize - dictSize);
                 dict = srcBuffer + dictStart;
             }
-            {   ZSTD_compressionParameters cPar = ZSTD_getCParams(cLevel, 0, dictSize);
+            {   ZSTD_compressionParameters const cPar = ZSTD_getCParams(cLevel, 0, dictSize);
                 U32 const checksum = FUZ_rand(&lseed) & 1;
                 U32 const noDictIDFlag = FUZ_rand(&lseed) & 1;
                 ZSTD_frameParameters const fPar = { 0, checksum, noDictIDFlag };
                 ZSTD_parameters params;
-                ZSTD_adjustCParams(&cPar, 0, dictSize);
                 params.cParams = cPar;
                 params.fParams = fPar;
                 {   size_t const initError = ZBUFF_compressInit_advanced(zc, dict, dictSize, params, 0);