]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Added support for forcing new CDict behavior and updated enum
authorSen Huang <senhuang96@fb.com>
Sun, 20 Oct 2019 18:03:09 +0000 (14:03 -0400)
committerSen Huang <senhuang96@fb.com>
Mon, 21 Oct 2019 19:36:12 +0000 (15:36 -0400)
lib/compress/zstd_compress.c
lib/zstd.h

index 634a0f85732a5af1c703662d2bd7506093dece95..ab5b13d019ac8c3c287bf6a74e31cd520b67ac70 100644 (file)
@@ -2908,7 +2908,8 @@ static size_t ZSTD_compressBegin_internal(ZSTD_CCtx* cctx,
     assert(!((dict) && (cdict)));  /* either dict or cdict, not both */
     if ( (cdict)
       && (cdict->dictContentSize > 0)
-      && (pledgedSrcSize < ZSTD_USE_CDICT_PARAMS_CUTOFF || cdict->compressionLevel == 0) ) {
+      && (pledgedSrcSize < ZSTD_USE_CDICT_PARAMS_CUTOFF || cdict->compressionLevel == 0)
+      && (params->attachDictPref != ZSTD_dictForceInputParams) ) {
         return ZSTD_resetCCtx_usingCDict(cctx, cdict, params, pledgedSrcSize, zbuff);
     }
 
index 66784562735cde9758a8d5871cf694709522aa41..4859733bbe384b3bfef96b4392fa344fc98e4271 100644 (file)
@@ -1149,7 +1149,7 @@ typedef enum {
      * to evolve and should be considered only in the context of extremely
      * advanced performance tuning.
      *
-     * Zstd currently supports the use of a CDict in two ways:
+     * Zstd currently supports the use of a CDict in three ways:
      *
      * - The contents of the CDict can be copied into the working context. This
      *   means that the compression can search both the dictionary and input
@@ -1164,6 +1164,10 @@ typedef enum {
      *   tables. However, this model incurs no start-up cost (as long as the
      *   working context's tables can be reused). For small inputs, this can be
      *   faster than copying the CDict's tables.
+     * 
+     * - The CDict's tables are not used at all, and instead we use the working
+     *   context alone to determine how our tables are initialized. This method
+     *   should be used when using a small dictionary to compress a large input.
      *
      * Zstd has a simple internal heuristic that selects which strategy to use
      * at the beginning of a compression. However, if experimentation shows that
@@ -1173,6 +1177,7 @@ typedef enum {
     ZSTD_dictDefaultAttach = 0, /* Use the default heuristic. */
     ZSTD_dictForceAttach   = 1, /* Never copy the dictionary. */
     ZSTD_dictForceCopy     = 2, /* Always copy the dictionary. */
+    ZSTD_dictForceInputParams = 3, /* Always use input to determine tables */
 } ZSTD_dictAttachPref_e;
 
 typedef enum {