]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Add a function for LDM enable check 2366/head
authorsenhuang42 <senhuang96@fb.com>
Tue, 20 Oct 2020 17:46:02 +0000 (13:46 -0400)
committersenhuang42 <senhuang96@fb.com>
Tue, 20 Oct 2020 17:46:02 +0000 (13:46 -0400)
lib/compress/zstd_compress.c

index 6d5da4b316524445fe3d92003ea183b1833a19cf..404f38dac69a124861d1cf92a8c4c529d1ba9f1b 100644 (file)
@@ -202,6 +202,14 @@ size_t ZSTD_sizeof_CStream(const ZSTD_CStream* zcs)
 /* private API call, for dictBuilder only */
 const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx) { return &(ctx->seqStore); }
 
+/* Returns 1 if compression parameters are such that we should
+ * enable long distance matching (wlog >= 27, strategy >= btopt).
+ * Returns 0 otherwise.
+ */
+static U32 ZSTD_CParams_shouldEnableLdm(const ZSTD_compressionParameters* const cParams) {
+    return cParams->strategy >= ZSTD_btopt && cParams->windowLog >= 27;
+}
+
 static ZSTD_CCtx_params ZSTD_makeCCtxParamsFromCParams(
         ZSTD_compressionParameters cParams)
 {
@@ -210,7 +218,7 @@ static ZSTD_CCtx_params ZSTD_makeCCtxParamsFromCParams(
     ZSTD_CCtxParams_init(&cctxParams, ZSTD_CLEVEL_DEFAULT);
     cctxParams.cParams = cParams;
 
-    if (cParams.strategy >= ZSTD_btopt && cParams.windowLog >= 27 && cctxParams.nbWorkers == 0) {
+    if (ZSTD_CParams_shouldEnableLdm(&cParams)) {
         DEBUGLOG(4, "ZSTD_makeCCtxParamsFromCParams(): Including LDM into cctx params");
         cctxParams.ldmParams.enableLdm = 1;
         /* LDM is enabled by default for optimal parser and window size >= 128MB */
@@ -4188,7 +4196,7 @@ size_t ZSTD_compressStream2( ZSTD_CCtx* cctx,
                     dictSize, mode);
         }
 
-        if (params.cParams.strategy >= ZSTD_btopt && params.cParams.windowLog >= 27) {
+        if (ZSTD_CParams_shouldEnableLdm(&params.cParams)) {
             /* Enable LDM by default for optimal parser and window size >= 128MB */
             DEBUGLOG(4, "LDM enabled by default (window size >= 128MB, strategy >= btopt)");
             params.ldmParams.enableLdm = 1;