]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Don't shrink window log in ZSTD_getCParams() 2451/head
authorNick Terrell <terrelln@fb.com>
Mon, 4 Jan 2021 23:51:23 +0000 (15:51 -0800)
committerNick Terrell <terrelln@fb.com>
Mon, 4 Jan 2021 23:54:09 +0000 (15:54 -0800)
Treat ZSTD_getCParams() and ZSTD_adjustCParams() in the same way
we treat streaming compression. Choose parameters based on the
dictionary size + source size, and assume the source size is small
if unkown. But, don't shrink the window log down in
ZSTD_adjustCParams_internal().

lib/compress/zstd_compress.c
tests/fuzzer.c

index c0628d832356660873f43f5103b0d1e158a0baf4..9e704a4b20f1d264d7d79c3b1d961d43023934e0 100644 (file)
@@ -1189,17 +1189,13 @@ ZSTD_adjustCParams_internal(ZSTD_compressionParameters cPar,
     assert(ZSTD_checkCParams(cPar)==0);
 
     switch (mode) {
+    case ZSTD_cpm_unknown:
     case ZSTD_cpm_noAttachDict:
         /* If we don't know the source size, don't make any
          * assumptions about it. We will already have selected
          * smaller parameters if a dictionary is in use.
          */
         break;
-    case ZSTD_cpm_unknown:
-        /* Keep the legacy behavior of assuming small source
-         * sizes when the cparam mode is unkown.
-         */
-        /* fall-through */
     case ZSTD_cpm_createCDict:
         /* Assume a small source size when creating a dictionary
          * with an unkown source size.
index c22871878fd7366f87c31022e8614f492e621d70..7e3b4628ec2373d695daaadd4865169e306594b1 100644 (file)
@@ -3051,6 +3051,32 @@ static int basicUnitTests(U32 const seed, double compressibility)
         free(dict);
     }
     DISPLAYLEVEL(3, "OK \n");
+
+    DISPLAYLEVEL(3, "test%3i : ZSTD_getCParams() + dictionary ", testNb++);
+    {
+        ZSTD_compressionParameters const medium = ZSTD_getCParams(1, 16*1024-1, 0);
+        ZSTD_compressionParameters const large = ZSTD_getCParams(1, 128*1024-1, 0);
+        ZSTD_compressionParameters const smallDict = ZSTD_getCParams(1, 0, 400);
+        ZSTD_compressionParameters const mediumDict = ZSTD_getCParams(1, 0, 10000);
+        ZSTD_compressionParameters const largeDict = ZSTD_getCParams(1, 0, 100000);
+
+        assert(!memcmp(&smallDict, &mediumDict, sizeof(smallDict)));
+        assert(!memcmp(&medium, &mediumDict, sizeof(medium)));
+        assert(!memcmp(&large, &largeDict, sizeof(large)));
+    }
+    DISPLAYLEVEL(3, "OK \n");
+
+    DISPLAYLEVEL(3, "test%3i : ZSTD_adjustCParams() + dictionary ", testNb++);
+    {
+        ZSTD_compressionParameters const cParams = ZSTD_getCParams(1, 0, 0);
+        ZSTD_compressionParameters const smallDict = ZSTD_adjustCParams(cParams, 0, 400);
+        ZSTD_compressionParameters const smallSrcAndDict = ZSTD_adjustCParams(cParams, 500, 400);
+
+        assert(smallSrcAndDict.windowLog == 10);
+        assert(!memcmp(&cParams, &smallDict, sizeof(cParams)));
+    }
+    DISPLAYLEVEL(3, "OK \n");
+
 #endif
 
 _end: