From: Yann Collet Date: Sat, 1 Apr 2017 00:11:38 +0000 (-0700) Subject: Changed ZSTD_compressBound() X-Git-Tag: v1.2.0^2~67^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f75d5252766bf0e638cf3fb7f5d63da50baaefe;p=thirdparty%2Fzstd.git Changed ZSTD_compressBound() required so that if Total = A+B compressBound(Total) <= compressBound(A) + compressBound(B) under condition of a minimum size for A and B Will help for ZSTDMT_compress() memory allocation --- diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index c31f8db91..cc69f1184 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -32,7 +32,10 @@ typedef enum { ZSTDcs_created=0, ZSTDcs_init, ZSTDcs_ongoing, ZSTDcs_ending } ZS * Helper functions ***************************************/ #define ZSTD_STATIC_ASSERT(c) { enum { ZSTD_static_assert = 1/(int)(!!(c)) }; } -size_t ZSTD_compressBound(size_t srcSize) { return FSE_compressBound(srcSize) + 12; } +size_t ZSTD_compressBound(size_t srcSize) { + size_t const margin = (srcSize < 512 KB) ? 16 : 0; + return srcSize + (srcSize >> 8) + margin; +} /*-*************************************