[lib] Add ZSTD_COMPRESS_HEAPMODE tuning parameter
This commit is contained in:
parent
b841387218
commit
6a1e526ea7
@ -36,6 +36,7 @@ libzstd:
|
||||
-DSTATIC_BMI2=0 \
|
||||
-DZSTD_ADDRESS_SANITIZER=0 \
|
||||
-DZSTD_MEMORY_SANITIZER=0 \
|
||||
-DZSTD_COMPRESS_HEAPMODE=1 \
|
||||
-UZSTD_NO_INLINE \
|
||||
-UNO_PREFETCH \
|
||||
-U__cplusplus \
|
||||
|
@ -29,6 +29,19 @@
|
||||
#include "zstd_ldm.h"
|
||||
#include "zstd_compress_superblock.h"
|
||||
|
||||
/* ***************************************************************
|
||||
* Tuning parameters
|
||||
*****************************************************************/
|
||||
/*!
|
||||
* COMPRESS_HEAPMODE :
|
||||
* Select how default decompression function ZSTD_compress() allocates its context,
|
||||
* on stack (0, default), or into heap (1).
|
||||
* Note that functions with explicit context such as ZSTD_compressCCtx() are unaffected.
|
||||
*/
|
||||
#ifndef ZSTD_COMPRESS_HEAPMODE
|
||||
# define ZSTD_COMPRESS_HEAPMODE 0
|
||||
#endif
|
||||
|
||||
|
||||
/*-*************************************
|
||||
* Helper functions
|
||||
@ -3370,10 +3383,17 @@ size_t ZSTD_compress(void* dst, size_t dstCapacity,
|
||||
int compressionLevel)
|
||||
{
|
||||
size_t result;
|
||||
#if ZSTD_COMPRESS_HEAPMODE
|
||||
ZSTD_CCtx* cctx = ZSTD_createCCtx();
|
||||
RETURN_ERROR_IF(!cctx, memory_allocation, "ZSTD_createCCtx failed");
|
||||
result = ZSTD_compressCCtx(cctx, dst, dstCapacity, src, srcSize, compressionLevel);
|
||||
ZSTD_freeCCtx(cctx);;
|
||||
#else
|
||||
ZSTD_CCtx ctxBody;
|
||||
ZSTD_initCCtx(&ctxBody, ZSTD_defaultCMem);
|
||||
result = ZSTD_compressCCtx(&ctxBody, dst, dstCapacity, src, srcSize, compressionLevel);
|
||||
ZSTD_freeCCtxContent(&ctxBody); /* can't free ctxBody itself, as it's on stack; free only heap content */
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user