Merge pull request #2805 from nolange/smaller_code_with_disabled_features
Smaller code with disabled featuresdev
commit
8b7a19fcd4
|
@ -255,11 +255,15 @@ static void ZSTD_initDCtx_internal(ZSTD_DCtx* dctx)
|
||||||
dctx->inBuffSize = 0;
|
dctx->inBuffSize = 0;
|
||||||
dctx->outBuffSize = 0;
|
dctx->outBuffSize = 0;
|
||||||
dctx->streamStage = zdss_init;
|
dctx->streamStage = zdss_init;
|
||||||
|
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
|
||||||
dctx->legacyContext = NULL;
|
dctx->legacyContext = NULL;
|
||||||
dctx->previousLegacyVersion = 0;
|
dctx->previousLegacyVersion = 0;
|
||||||
|
#endif
|
||||||
dctx->noForwardProgress = 0;
|
dctx->noForwardProgress = 0;
|
||||||
dctx->oversizedDuration = 0;
|
dctx->oversizedDuration = 0;
|
||||||
|
#if DYNAMIC_BMI2
|
||||||
dctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid());
|
dctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid());
|
||||||
|
#endif
|
||||||
dctx->ddictSet = NULL;
|
dctx->ddictSet = NULL;
|
||||||
ZSTD_DCtx_resetParameters(dctx);
|
ZSTD_DCtx_resetParameters(dctx);
|
||||||
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
||||||
|
@ -280,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);
|
||||||
|
@ -292,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)
|
||||||
|
@ -1078,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);
|
||||||
|
@ -1543,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)
|
||||||
|
@ -1553,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)
|
||||||
|
@ -1947,7 +1955,9 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
|
||||||
DEBUGLOG(5, "stage zdss_init => transparent reset ");
|
DEBUGLOG(5, "stage zdss_init => transparent reset ");
|
||||||
zds->streamStage = zdss_loadHeader;
|
zds->streamStage = zdss_loadHeader;
|
||||||
zds->lhSize = zds->inPos = zds->outStart = zds->outEnd = 0;
|
zds->lhSize = zds->inPos = zds->outStart = zds->outEnd = 0;
|
||||||
|
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
|
||||||
zds->legacyVersion = 0;
|
zds->legacyVersion = 0;
|
||||||
|
#endif
|
||||||
zds->hostageByte = 0;
|
zds->hostageByte = 0;
|
||||||
zds->expectedOutBuffer = *output;
|
zds->expectedOutBuffer = *output;
|
||||||
ZSTD_FALLTHROUGH;
|
ZSTD_FALLTHROUGH;
|
||||||
|
|
|
@ -133,11 +133,11 @@ size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx,
|
||||||
if (singleStream) {
|
if (singleStream) {
|
||||||
hufSuccess = HUF_decompress1X_usingDTable_bmi2(
|
hufSuccess = HUF_decompress1X_usingDTable_bmi2(
|
||||||
dctx->litBuffer, litSize, istart+lhSize, litCSize,
|
dctx->litBuffer, litSize, istart+lhSize, litCSize,
|
||||||
dctx->HUFptr, dctx->bmi2);
|
dctx->HUFptr, ZSTD_DCtx_get_bmi2(dctx));
|
||||||
} else {
|
} else {
|
||||||
hufSuccess = HUF_decompress4X_usingDTable_bmi2(
|
hufSuccess = HUF_decompress4X_usingDTable_bmi2(
|
||||||
dctx->litBuffer, litSize, istart+lhSize, litCSize,
|
dctx->litBuffer, litSize, istart+lhSize, litCSize,
|
||||||
dctx->HUFptr, dctx->bmi2);
|
dctx->HUFptr, ZSTD_DCtx_get_bmi2(dctx));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (singleStream) {
|
if (singleStream) {
|
||||||
|
@ -150,13 +150,13 @@ size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx,
|
||||||
hufSuccess = HUF_decompress1X1_DCtx_wksp_bmi2(
|
hufSuccess = HUF_decompress1X1_DCtx_wksp_bmi2(
|
||||||
dctx->entropy.hufTable, dctx->litBuffer, litSize,
|
dctx->entropy.hufTable, dctx->litBuffer, litSize,
|
||||||
istart+lhSize, litCSize, dctx->workspace,
|
istart+lhSize, litCSize, dctx->workspace,
|
||||||
sizeof(dctx->workspace), dctx->bmi2);
|
sizeof(dctx->workspace), ZSTD_DCtx_get_bmi2(dctx));
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
hufSuccess = HUF_decompress4X_hufOnly_wksp_bmi2(
|
hufSuccess = HUF_decompress4X_hufOnly_wksp_bmi2(
|
||||||
dctx->entropy.hufTable, dctx->litBuffer, litSize,
|
dctx->entropy.hufTable, dctx->litBuffer, litSize,
|
||||||
istart+lhSize, litCSize, dctx->workspace,
|
istart+lhSize, litCSize, dctx->workspace,
|
||||||
sizeof(dctx->workspace), dctx->bmi2);
|
sizeof(dctx->workspace), ZSTD_DCtx_get_bmi2(dctx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,7 +620,7 @@ size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
|
||||||
LL_defaultDTable, dctx->fseEntropy,
|
LL_defaultDTable, dctx->fseEntropy,
|
||||||
dctx->ddictIsCold, nbSeq,
|
dctx->ddictIsCold, nbSeq,
|
||||||
dctx->workspace, sizeof(dctx->workspace),
|
dctx->workspace, sizeof(dctx->workspace),
|
||||||
dctx->bmi2);
|
ZSTD_DCtx_get_bmi2(dctx));
|
||||||
RETURN_ERROR_IF(ZSTD_isError(llhSize), corruption_detected, "ZSTD_buildSeqTable failed");
|
RETURN_ERROR_IF(ZSTD_isError(llhSize), corruption_detected, "ZSTD_buildSeqTable failed");
|
||||||
ip += llhSize;
|
ip += llhSize;
|
||||||
}
|
}
|
||||||
|
@ -632,7 +632,7 @@ size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
|
||||||
OF_defaultDTable, dctx->fseEntropy,
|
OF_defaultDTable, dctx->fseEntropy,
|
||||||
dctx->ddictIsCold, nbSeq,
|
dctx->ddictIsCold, nbSeq,
|
||||||
dctx->workspace, sizeof(dctx->workspace),
|
dctx->workspace, sizeof(dctx->workspace),
|
||||||
dctx->bmi2);
|
ZSTD_DCtx_get_bmi2(dctx));
|
||||||
RETURN_ERROR_IF(ZSTD_isError(ofhSize), corruption_detected, "ZSTD_buildSeqTable failed");
|
RETURN_ERROR_IF(ZSTD_isError(ofhSize), corruption_detected, "ZSTD_buildSeqTable failed");
|
||||||
ip += ofhSize;
|
ip += ofhSize;
|
||||||
}
|
}
|
||||||
|
@ -644,7 +644,7 @@ size_t ZSTD_decodeSeqHeaders(ZSTD_DCtx* dctx, int* nbSeqPtr,
|
||||||
ML_defaultDTable, dctx->fseEntropy,
|
ML_defaultDTable, dctx->fseEntropy,
|
||||||
dctx->ddictIsCold, nbSeq,
|
dctx->ddictIsCold, nbSeq,
|
||||||
dctx->workspace, sizeof(dctx->workspace),
|
dctx->workspace, sizeof(dctx->workspace),
|
||||||
dctx->bmi2);
|
ZSTD_DCtx_get_bmi2(dctx));
|
||||||
RETURN_ERROR_IF(ZSTD_isError(mlhSize), corruption_detected, "ZSTD_buildSeqTable failed");
|
RETURN_ERROR_IF(ZSTD_isError(mlhSize), corruption_detected, "ZSTD_buildSeqTable failed");
|
||||||
ip += mlhSize;
|
ip += mlhSize;
|
||||||
}
|
}
|
||||||
|
@ -1379,7 +1379,7 @@ ZSTD_decompressSequences(ZSTD_DCtx* dctx, void* dst, size_t maxDstSize,
|
||||||
{
|
{
|
||||||
DEBUGLOG(5, "ZSTD_decompressSequences");
|
DEBUGLOG(5, "ZSTD_decompressSequences");
|
||||||
#if DYNAMIC_BMI2
|
#if DYNAMIC_BMI2
|
||||||
if (dctx->bmi2) {
|
if (ZSTD_DCtx_get_bmi2(dctx)) {
|
||||||
return ZSTD_decompressSequences_bmi2(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset, frame);
|
return ZSTD_decompressSequences_bmi2(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset, frame);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1403,7 +1403,7 @@ ZSTD_decompressSequencesLong(ZSTD_DCtx* dctx,
|
||||||
{
|
{
|
||||||
DEBUGLOG(5, "ZSTD_decompressSequencesLong");
|
DEBUGLOG(5, "ZSTD_decompressSequencesLong");
|
||||||
#if DYNAMIC_BMI2
|
#if DYNAMIC_BMI2
|
||||||
if (dctx->bmi2) {
|
if (ZSTD_DCtx_get_bmi2(dctx)) {
|
||||||
return ZSTD_decompressSequencesLong_bmi2(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset, frame);
|
return ZSTD_decompressSequencesLong_bmi2(dctx, dst, maxDstSize, seqStart, seqSize, nbSeq, isLongOffset, frame);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -136,7 +136,9 @@ struct ZSTD_DCtx_s
|
||||||
size_t litSize;
|
size_t litSize;
|
||||||
size_t rleSize;
|
size_t rleSize;
|
||||||
size_t staticSize;
|
size_t staticSize;
|
||||||
|
#if DYNAMIC_BMI2 != 0
|
||||||
int bmi2; /* == 1 if the CPU supports BMI2 and 0 otherwise. CPU support is determined dynamically once per context lifetime. */
|
int bmi2; /* == 1 if the CPU supports BMI2 and 0 otherwise. CPU support is determined dynamically once per context lifetime. */
|
||||||
|
#endif
|
||||||
|
|
||||||
/* dictionary */
|
/* dictionary */
|
||||||
ZSTD_DDict* ddictLocal;
|
ZSTD_DDict* ddictLocal;
|
||||||
|
@ -158,9 +160,11 @@ struct ZSTD_DCtx_s
|
||||||
size_t outStart;
|
size_t outStart;
|
||||||
size_t outEnd;
|
size_t outEnd;
|
||||||
size_t lhSize;
|
size_t lhSize;
|
||||||
|
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT>=1)
|
||||||
void* legacyContext;
|
void* legacyContext;
|
||||||
U32 previousLegacyVersion;
|
U32 previousLegacyVersion;
|
||||||
U32 legacyVersion;
|
U32 legacyVersion;
|
||||||
|
#endif
|
||||||
U32 hostageByte;
|
U32 hostageByte;
|
||||||
int noForwardProgress;
|
int noForwardProgress;
|
||||||
ZSTD_bufferMode_e outBufferMode;
|
ZSTD_bufferMode_e outBufferMode;
|
||||||
|
@ -183,6 +187,14 @@ struct ZSTD_DCtx_s
|
||||||
#endif
|
#endif
|
||||||
}; /* typedef'd to ZSTD_DCtx within "zstd.h" */
|
}; /* typedef'd to ZSTD_DCtx within "zstd.h" */
|
||||||
|
|
||||||
|
MEM_STATIC int ZSTD_DCtx_get_bmi2(const struct ZSTD_DCtx_s *dctx) {
|
||||||
|
#if DYNAMIC_BMI2 != 0
|
||||||
|
return dctx->bmi2;
|
||||||
|
#else
|
||||||
|
(void)dctx;
|
||||||
|
return 0;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/*-*******************************************************
|
/*-*******************************************************
|
||||||
* Shared internal functions
|
* Shared internal functions
|
||||||
|
|
|
@ -177,7 +177,7 @@ FORCE_NOINLINE size_t ZSTD_decodeLiteralsHeader(ZSTD_DCtx* dctx, void const* src
|
||||||
dctx->entropy.hufTable,
|
dctx->entropy.hufTable,
|
||||||
istart+lhSize, litCSize,
|
istart+lhSize, litCSize,
|
||||||
dctx->workspace, sizeof(dctx->workspace),
|
dctx->workspace, sizeof(dctx->workspace),
|
||||||
dctx->bmi2);
|
ZSTD_DCtx_get_bmi2(dctx));
|
||||||
#else
|
#else
|
||||||
return HUF_readDTableX2_wksp(
|
return HUF_readDTableX2_wksp(
|
||||||
dctx->entropy.hufTable,
|
dctx->entropy.hufTable,
|
||||||
|
|
Loading…
Reference in New Issue