mirror of
https://github.com/facebook/zstd.git
synced 2025-08-01 09:47:01 +03:00
[lib] Add ZSTD_COMPRESS_HEAPMODE tuning parameter
This commit is contained in:
@ -36,6 +36,7 @@ libzstd:
|
|||||||
-DSTATIC_BMI2=0 \
|
-DSTATIC_BMI2=0 \
|
||||||
-DZSTD_ADDRESS_SANITIZER=0 \
|
-DZSTD_ADDRESS_SANITIZER=0 \
|
||||||
-DZSTD_MEMORY_SANITIZER=0 \
|
-DZSTD_MEMORY_SANITIZER=0 \
|
||||||
|
-DZSTD_COMPRESS_HEAPMODE=1 \
|
||||||
-UZSTD_NO_INLINE \
|
-UZSTD_NO_INLINE \
|
||||||
-UNO_PREFETCH \
|
-UNO_PREFETCH \
|
||||||
-U__cplusplus \
|
-U__cplusplus \
|
||||||
|
@ -29,6 +29,19 @@
|
|||||||
#include "zstd_ldm.h"
|
#include "zstd_ldm.h"
|
||||||
#include "zstd_compress_superblock.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
|
* Helper functions
|
||||||
@ -3370,10 +3383,17 @@ size_t ZSTD_compress(void* dst, size_t dstCapacity,
|
|||||||
int compressionLevel)
|
int compressionLevel)
|
||||||
{
|
{
|
||||||
size_t result;
|
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_CCtx ctxBody;
|
||||||
ZSTD_initCCtx(&ctxBody, ZSTD_defaultCMem);
|
ZSTD_initCCtx(&ctxBody, ZSTD_defaultCMem);
|
||||||
result = ZSTD_compressCCtx(&ctxBody, dst, dstCapacity, src, srcSize, compressionLevel);
|
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 */
|
ZSTD_freeCCtxContent(&ctxBody); /* can't free ctxBody itself, as it's on stack; free only heap content */
|
||||||
|
#endif
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user