From: Yann Collet Date: Thu, 29 Jun 2017 03:17:22 +0000 (-0700) Subject: refactor ZSTD_check_compressionLevel_monotonicIncrease_memoryBudget() X-Git-Tag: v1.3.0~1^2~10^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F739%2Fhead;p=thirdparty%2Fzstd.git refactor ZSTD_check_compressionLevel_monotonicIncrease_memoryBudget() use less macro statements the initial version was meant to work with STATIC_ASSERT but since it doesn't work and needs assert() it's possible to rewrite it using normally compiled code which is better for compiler. Downside : the error message is less precise. There is a DEBUGLOG(3,) to compensate. --- diff --git a/doc/zstd_manual.html b/doc/zstd_manual.html index 683b70e80..cd2b06dd8 100644 --- a/doc/zstd_manual.html +++ b/doc/zstd_manual.html @@ -412,7 +412,7 @@ size_t ZSTD_estimateCCtxSize_advanced(ZSTD_compressionParameters cParams); size_t ZSTD_estimateDCtxSize(void);

These functions make it possible to estimate memory usage of a future {D,C}Ctx, before its creation. - ZSTD_estimateCCtxSize() will provide a budget large for any compression level up to selected one. + ZSTD_estimateCCtxSize() will provide a budget large enough for any compression level up to selected one. It will also consider src size to be arbitrarily "large", which is worst case. If srcSize is known to always be small, ZSTD_estimateCCtxSize_advanced() can provide a tighter estimation. ZSTD_estimateCCtxSize_advanced() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel. @@ -423,7 +423,7 @@ size_t ZSTD_estimateDCtxSize(void); size_t ZSTD_estimateCStreamSize_advanced(ZSTD_compressionParameters cParams); size_t ZSTD_estimateDStreamSize(size_t windowSize); size_t ZSTD_estimateDStreamSize_fromFrame(const void* src, size_t srcSize); -

ZSTD_estimateCStreamSize() will provide a budget large for any compression level up to selected one. +

ZSTD_estimateCStreamSize() will provide a budget large enough for any compression level up to selected one. It will also consider src size to be arbitrarily "large", which is worst case. If srcSize is known to always be small, ZSTD_estimateCStreamSize_advanced() can provide a tighter estimation. ZSTD_estimateCStreamSize_advanced() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel. diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index b396311d3..f492d92bd 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -4115,42 +4115,24 @@ static const ZSTD_compressionParameters ZSTD_defaultCParameters[4][ZSTD_MAX_CLEV }, }; +#if defined(ZSTD_DEBUG) && (ZSTD_DEBUG>=1) /* This function just controls * the monotonic memory budget increase of ZSTD_defaultCParameters[0]. * Run only once, on first ZSTD_getCParams() usage, when ZSTD_DEBUG is enabled */ MEM_STATIC void ZSTD_check_compressionLevel_monotonicIncrease_memoryBudget(void) { -# define ZSTD_TABLECOST(h,c) ((1<<(h)) + (1<<(c))) -# define ZDCP_FIELD(l,field) (ZSTD_defaultCParameters[0][l].field) -# define ZSTD_CHECK_MONOTONIC_INCREASE_LEVEL(l) { \ - assert(ZDCP_FIELD(l,windowLog) <= ZDCP_FIELD(l+1,windowLog) ); \ - assert(ZSTD_TABLECOST(ZDCP_FIELD(l,hashLog), ZDCP_FIELD(l,chainLog)) <= ZSTD_TABLECOST(ZDCP_FIELD(l+1,hashLog), ZDCP_FIELD(l+1,chainLog)) ); \ + int level; + for (level=1; level