[libzstd] Switch dictUses to an enum
diff --git a/lib/decompress/zstd_decompress.c b/lib/decompress/zstd_decompress.c
index bd955d6..4f29227 100644
--- a/lib/decompress/zstd_decompress.c
+++ b/lib/decompress/zstd_decompress.c
@@ -106,7 +106,7 @@
dctx->ddictLocal = NULL;
dctx->dictEnd = NULL;
dctx->ddictIsCold = 0;
- dctx->dictUsesRemaining = 0;
+ dctx->dictUses = ZSTD_dont_use;
dctx->inBuff = NULL;
dctx->inBuffSize = 0;
dctx->outBuffSize = 0;
@@ -153,7 +153,7 @@
ZSTD_freeDDict(dctx->ddictLocal);
dctx->ddictLocal = NULL;
dctx->ddict = NULL;
- dctx->dictUsesRemaining = 0;
+ dctx->dictUses = ZSTD_dont_use;
}
size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx)
@@ -796,15 +796,19 @@
static ZSTD_DDict const* ZSTD_getDDict(ZSTD_DCtx* dctx)
{
- if (dctx->dictUsesRemaining == 0) {
+ switch (dctx->dictUses) {
+ default:
+ assert(0 /* Impossible */);
+ /* fall-through */
+ case ZSTD_dont_use:
ZSTD_clearDict(dctx);
return NULL;
- }
- if (dctx->dictUsesRemaining < 0) {
+ case ZSTD_use_indefinitely:
+ return dctx->ddict;
+ case ZSTD_use_once:
+ dctx->dictUses = ZSTD_dont_use;
return dctx->ddict;
}
- --dctx->dictUsesRemaining;
- return dctx->ddict;
}
size_t ZSTD_decompressDCtx(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, const void* src, size_t srcSize)
@@ -1261,7 +1265,7 @@
dctx->ddictLocal = ZSTD_createDDict_advanced(dict, dictSize, dictLoadMethod, dictContentType, dctx->customMem);
RETURN_ERROR_IF(dctx->ddictLocal == NULL, memory_allocation);
dctx->ddict = dctx->ddictLocal;
- dctx->dictUsesRemaining = -1;
+ dctx->dictUses = ZSTD_use_indefinitely;
}
return 0;
}
@@ -1279,7 +1283,7 @@
size_t ZSTD_DCtx_refPrefix_advanced(ZSTD_DCtx* dctx, const void* prefix, size_t prefixSize, ZSTD_dictContentType_e dictContentType)
{
FORWARD_IF_ERROR(ZSTD_DCtx_loadDictionary_advanced(dctx, prefix, prefixSize, ZSTD_dlm_byRef, dictContentType));
- dctx->dictUsesRemaining = 1;
+ dctx->dictUses = ZSTD_use_once;
return 0;
}
@@ -1333,7 +1337,7 @@
ZSTD_clearDict(dctx);
if (ddict) {
dctx->ddict = ddict;
- dctx->dictUsesRemaining = -1;
+ dctx->dictUses = ZSTD_use_indefinitely;
}
return 0;
}
diff --git a/lib/decompress/zstd_decompress_internal.h b/lib/decompress/zstd_decompress_internal.h
index ea07243..ccbdfa0 100644
--- a/lib/decompress/zstd_decompress_internal.h
+++ b/lib/decompress/zstd_decompress_internal.h
@@ -89,6 +89,12 @@
typedef enum { zdss_init=0, zdss_loadHeader,
zdss_read, zdss_load, zdss_flush } ZSTD_dStreamStage;
+typedef enum {
+ ZSTD_use_indefinitely = -1, /* Use the dictionary indefinitely */
+ ZSTD_dont_use = 0, /* Do not use the dictionary (if one exists free it) */
+ ZSTD_use_once = 1 /* Use the dictionary once and set to ZSTD_dont_use */
+} ZSTD_dictUses_e;
+
struct ZSTD_DCtx_s
{
const ZSTD_seqSymbol* LLTptr;
@@ -123,9 +129,7 @@
const ZSTD_DDict* ddict; /* set by ZSTD_initDStream_usingDDict(), or ZSTD_DCtx_refDDict() */
U32 dictID;
int ddictIsCold; /* if == 1 : dictionary is "new" for working context, and presumed "cold" (not in cpu cache) */
- int dictUsesRemaining; /* if == 1 : dictionary should be used once.
- * if == 0 : dictionary should be forgotten now.
- * if < 0 : dictionary should be used indefinitely. */
+ ZSTD_dictUses_e dictUses;
/* streaming */
ZSTD_dStreamStage streamStage;