From: Nick Terrell Date: Thu, 11 Jan 2018 22:35:04 +0000 (-0800) Subject: Increase windowLog from CDict based on the srcSize when known X-Git-Tag: v1.3.4~1^2~86^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b610b777d39c9eee139e7b73f32db5e2eafbd2e9;p=thirdparty%2Fzstd.git Increase windowLog from CDict based on the srcSize when known --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index b9e0ec44d..d11fbeb3c 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -2453,6 +2453,15 @@ size_t ZSTD_compressBegin_usingCDict_advanced( if (cdict==NULL) return ERROR(dictionary_wrong); { ZSTD_CCtx_params params = cctx->requestedParams; params.cParams = ZSTD_getCParamsFromCDict(cdict); + /* Increase window log to fit the entire dictionary and source if the + * source size is known. Limit the increase to 19, which is the + * window log for compression level 1 with the largest source size. + */ + if (pledgedSrcSize != ZSTD_CONTENTSIZE_UNKNOWN) { + U32 const limitedSrcSize = (U32)MIN(pledgedSrcSize, 1U << 19); + U32 const limitedSrcLog = limitedSrcSize > 1 ? ZSTD_highbit32(limitedSrcSize - 1) + 1 : 1; + params.cParams.windowLog = MAX(params.cParams.windowLog, limitedSrcLog); + } params.fParams = fParams; return ZSTD_compressBegin_internal(cctx, NULL, 0, ZSTD_dm_auto,