From 5b10345b263df7cf5aa078c3a084b3254a72326e Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 29 Sep 2017 23:17:41 -0700 Subject: [PATCH] added ZSTD_COMPRESSBOUND() as a macro ZSTD_compressBound() works fine, but is only useful for dynamic allocation. For static allocation, only a macro can provide the amount during compilation time. --- lib/compress/zstd_compress.c | 4 +--- lib/zstd.h | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/compress/zstd_compress.c b/lib/compress/zstd_compress.c index 4c2254abe..d234903b5 100644 --- a/lib/compress/zstd_compress.c +++ b/lib/compress/zstd_compress.c @@ -38,9 +38,7 @@ * Helper functions ***************************************/ size_t ZSTD_compressBound(size_t srcSize) { - size_t const lowLimit = 256 KB; - size_t const margin = (srcSize < lowLimit) ? (lowLimit-srcSize) >> 12 : 0; /* from 64 to 0 */ - return srcSize + (srcSize >> 8) + margin; + return ZSTD_COMPRESSBOUND(srcSize); } diff --git a/lib/zstd.h b/lib/zstd.h index 02241fd3f..5f3c0585f 100644 --- a/lib/zstd.h +++ b/lib/zstd.h @@ -131,10 +131,11 @@ ZSTDLIB_API unsigned long long ZSTD_getDecompressedSize(const void* src, size_t /*====== Helper functions ======*/ -ZSTDLIB_API int ZSTD_maxCLevel(void); /*!< maximum compression level available */ +#define ZSTD_COMPRESSBOUND(srcSize) ((srcSize) + ((srcSize)>>9) + (((srcSize) < 128 KB) ? ((128 KB - (srcSize)) >> 11) /* margin, from 64 to 0 */ : 0)) ZSTDLIB_API size_t ZSTD_compressBound(size_t srcSize); /*!< maximum compressed size in worst case scenario */ ZSTDLIB_API unsigned ZSTD_isError(size_t code); /*!< tells if a `size_t` function result is an error code */ ZSTDLIB_API const char* ZSTD_getErrorName(size_t code); /*!< provides readable string from an error code */ +ZSTDLIB_API int ZSTD_maxCLevel(void); /*!< maximum compression level available */ /***************************************