mirror of
https://github.com/facebook/zstd.git
synced 2025-10-06 00:04:13 -04:00
zstd_decompress: use a helper function for context create
Multiple ZSTD_createDCtx* functions call other (public) ZSTD_createDCtx* functions, this makes it harder for humans and compilers to throw out code that is not used. This farms out the logic into a static function, if a program only uses a single ZSTD_createDCtx variant, all others can be easily dropped and the remaining implementation can be specialized.
This commit is contained in:
parent
0d45540695
commit
6763f40331
@ -262,7 +262,7 @@ static void ZSTD_initDCtx_internal(ZSTD_DCtx* dctx)
|
|||||||
dctx->noForwardProgress = 0;
|
dctx->noForwardProgress = 0;
|
||||||
dctx->oversizedDuration = 0;
|
dctx->oversizedDuration = 0;
|
||||||
#if DYNAMIC_BMI2
|
#if DYNAMIC_BMI2
|
||||||
dctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid())
|
dctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid());
|
||||||
#endif
|
#endif
|
||||||
dctx->ddictSet = NULL;
|
dctx->ddictSet = NULL;
|
||||||
ZSTD_DCtx_resetParameters(dctx);
|
ZSTD_DCtx_resetParameters(dctx);
|
||||||
@ -284,8 +284,7 @@ ZSTD_DCtx* ZSTD_initStaticDCtx(void *workspace, size_t workspaceSize)
|
|||||||
return dctx;
|
return dctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem)
|
static ZSTD_DCtx* ZSTD_createDCtx_internal(ZSTD_customMem customMem) {
|
||||||
{
|
|
||||||
if ((!customMem.customAlloc) ^ (!customMem.customFree)) return NULL;
|
if ((!customMem.customAlloc) ^ (!customMem.customFree)) return NULL;
|
||||||
|
|
||||||
{ ZSTD_DCtx* const dctx = (ZSTD_DCtx*)ZSTD_customMalloc(sizeof(*dctx), customMem);
|
{ ZSTD_DCtx* const dctx = (ZSTD_DCtx*)ZSTD_customMalloc(sizeof(*dctx), customMem);
|
||||||
@ -296,10 +295,15 @@ ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem)
|
||||||
|
{
|
||||||
|
return ZSTD_createDCtx_internal(customMem);
|
||||||
|
}
|
||||||
|
|
||||||
ZSTD_DCtx* ZSTD_createDCtx(void)
|
ZSTD_DCtx* ZSTD_createDCtx(void)
|
||||||
{
|
{
|
||||||
DEBUGLOG(3, "ZSTD_createDCtx");
|
DEBUGLOG(3, "ZSTD_createDCtx");
|
||||||
return ZSTD_createDCtx_advanced(ZSTD_defaultCMem);
|
return ZSTD_createDCtx_internal(ZSTD_defaultCMem);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ZSTD_clearDict(ZSTD_DCtx* dctx)
|
static void ZSTD_clearDict(ZSTD_DCtx* dctx)
|
||||||
@ -1082,7 +1086,7 @@ size_t ZSTD_decompress(void* dst, size_t dstCapacity, const void* src, size_t sr
|
|||||||
{
|
{
|
||||||
#if defined(ZSTD_HEAPMODE) && (ZSTD_HEAPMODE>=1)
|
#if defined(ZSTD_HEAPMODE) && (ZSTD_HEAPMODE>=1)
|
||||||
size_t regenSize;
|
size_t regenSize;
|
||||||
ZSTD_DCtx* const dctx = ZSTD_createDCtx();
|
ZSTD_DCtx* const dctx = ZSTD_createDCtx_internal(ZSTD_defaultCMem);
|
||||||
RETURN_ERROR_IF(dctx==NULL, memory_allocation, "NULL pointer!");
|
RETURN_ERROR_IF(dctx==NULL, memory_allocation, "NULL pointer!");
|
||||||
regenSize = ZSTD_decompressDCtx(dctx, dst, dstCapacity, src, srcSize);
|
regenSize = ZSTD_decompressDCtx(dctx, dst, dstCapacity, src, srcSize);
|
||||||
ZSTD_freeDCtx(dctx);
|
ZSTD_freeDCtx(dctx);
|
||||||
@ -1547,7 +1551,7 @@ size_t ZSTD_decompress_usingDDict(ZSTD_DCtx* dctx,
|
|||||||
ZSTD_DStream* ZSTD_createDStream(void)
|
ZSTD_DStream* ZSTD_createDStream(void)
|
||||||
{
|
{
|
||||||
DEBUGLOG(3, "ZSTD_createDStream");
|
DEBUGLOG(3, "ZSTD_createDStream");
|
||||||
return ZSTD_createDStream_advanced(ZSTD_defaultCMem);
|
return ZSTD_createDCtx_internal(ZSTD_defaultCMem);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZSTD_DStream* ZSTD_initStaticDStream(void *workspace, size_t workspaceSize)
|
ZSTD_DStream* ZSTD_initStaticDStream(void *workspace, size_t workspaceSize)
|
||||||
@ -1557,7 +1561,7 @@ ZSTD_DStream* ZSTD_initStaticDStream(void *workspace, size_t workspaceSize)
|
|||||||
|
|
||||||
ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem)
|
ZSTD_DStream* ZSTD_createDStream_advanced(ZSTD_customMem customMem)
|
||||||
{
|
{
|
||||||
return ZSTD_createDCtx_advanced(customMem);
|
return ZSTD_createDCtx_internal(customMem);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t ZSTD_freeDStream(ZSTD_DStream* zds)
|
size_t ZSTD_freeDStream(ZSTD_DStream* zds)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user