From: Yann Collet Date: Wed, 1 Nov 2017 20:15:23 +0000 (-0700) Subject: fix : ZSTD_compress_generic(,,,ZSTD_e_end) automatically sets pledgedSrcSize X-Git-Tag: v1.3.3^2~43^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=428e8b3bf49ed9d36e732acf634d6150d0e2b302;p=thirdparty%2Fzstd.git fix : ZSTD_compress_generic(,,,ZSTD_e_end) automatically sets pledgedSrcSize as per documentation, on ZSTD_setPledgedSrcSize() : > If all data is provided and consumed in a single round, > this value (pledgedSrcSize) is overriden by srcSize instead. This wasn't applied before compression level is transformed into compression parameters. As a consequence, small input missed compression parameters adaptation. It seems to work fine now : compression was compared with ZSTD_compress_advanced(), results were the same. --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 21b84d104..d50f35116 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -2814,6 +2814,7 @@ size_t ZSTD_compress_generic (ZSTD_CCtx* cctx, if (cctx->streamStage == zcss_init) { ZSTD_prefixDict const prefixDict = cctx->prefixDict; ZSTD_CCtx_params params = cctx->requestedParams; + if (endOp == ZSTD_e_end) cctx->pledgedSrcSizePlusOne = input->size + 1; params.cParams = ZSTD_getCParamsFromCCtxParams( cctx->requestedParams, cctx->pledgedSrcSizePlusOne-1, 0 /*dictSize*/); memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict)); /* single usage */ diff --git a/programs/bench.c b/programs/bench.c index 8ecae9ebd..66c406abd 100644 --- a/programs/bench.c +++ b/programs/bench.c @@ -286,6 +286,7 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize, U32 nbLoops = 0; ZSTD_CCtx_setParameter(ctx, ZSTD_p_nbThreads, g_nbThreads); ZSTD_CCtx_setParameter(ctx, ZSTD_p_compressionLevel, cLevel); + //ZSTD_CCtx_setPledgedSrcSize(ctx, blockTable[0].srcSize); /* estimation, only to help cLevel conversion before applying advanced compression parameters */ ZSTD_CCtx_setParameter(ctx, ZSTD_p_enableLongDistanceMatching, g_ldmFlag); ZSTD_CCtx_setParameter(ctx, ZSTD_p_ldmMinMatch, g_ldmMinMatch); ZSTD_CCtx_setParameter(ctx, ZSTD_p_ldmHashLog, g_ldmHashLog); @@ -305,6 +306,14 @@ static int BMK_benchMem(const void* srcBuffer, size_t srcSize, do { U32 blockNb; for (blockNb=0; blockNb