]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
added ZSTD_COMPRESSBOUND() as a macro
authorYann Collet <cyan@fb.com>
Sat, 30 Sep 2017 06:17:41 +0000 (23:17 -0700)
committerYann Collet <cyan@fb.com>
Sat, 30 Sep 2017 06:17:41 +0000 (23:17 -0700)
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
lib/zstd.h

index 4c2254abe9c9abc5e8267743bf7d7af30ad3aa36..d234903b5264e4aaa950e810f7a0102aa2f98982 100644 (file)
@@ -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);
 }
 
 
index 02241fd3fbfe38201bad93a42839fb1b7f533f10..5f3c0585f6be15be1f377cbc6a8b9570512bc0bb 100644 (file)
@@ -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 */
 
 
 /***************************************