From: senhuang42 Date: Tue, 20 Oct 2020 17:46:02 +0000 (-0400) Subject: Add a function for LDM enable check X-Git-Tag: v1.4.7~44^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8bdb32aebe181ebfa62237be49e9d183c2daf596;p=thirdparty%2Fzstd.git Add a function for LDM enable check --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 6d5da4b31..404f38dac 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -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(¶ms.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;