]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Increase windowLog from CDict based on the srcSize when known
authorNick Terrell <terrelln@fb.com>
Thu, 11 Jan 2018 22:35:04 +0000 (14:35 -0800)
committerNick Terrell <terrelln@fb.com>
Fri, 12 Jan 2018 00:23:21 +0000 (16:23 -0800)
lib/compress/zstd_compress.c

index b9e0ec44ddd5a6c213668e69d73d9144aa995283..d11fbeb3c48d2df079c04645e365856ec00d407e 100644 (file)
@@ -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,