]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Only Reset Indexing in `ZSTD_resetCCtx_internal()` When Necessary
authorW. Felix Handte <w@felixhandte.com>
Tue, 10 Sep 2019 21:55:41 +0000 (17:55 -0400)
committerW. Felix Handte <w@felixhandte.com>
Tue, 10 Sep 2019 22:25:45 +0000 (18:25 -0400)
lib/compress/zstd_compress.c

index 21b13fa80f95f18346f63bee563c584cdf61bc3b..ec7e78363ab0eae59ffa1ace84bbd4a97faf9b27 100644 (file)
@@ -1398,6 +1398,14 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
         size_t const matchStateSize = ZSTD_sizeof_matchState(&params.cParams, /* forCCtx */ 1);
         size_t const maxNbLdmSeq = ZSTD_ldm_getMaxNbSeq(params.ldmParams, blockSize);
 
+        ZSTD_indexResetPolicy_e needsIndexReset = ZSTDirp_continue;
+
+        if (ZSTD_indexTooCloseToMax(zc->blockState.matchState.window)) {
+            needsIndexReset = ZSTDirp_reset;
+        }
+
+        ZSTD_cwksp_bump_oversized_duration(ws, 0);
+
         /* Check if workspace is large enough, alloc a new one if needed */
         {   size_t const cctxSpace = zc->staticSize ? sizeof(ZSTD_CCtx) : 0;
             size_t const entropySpace = HUF_WORKSPACE_SIZE;
@@ -1430,6 +1438,8 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
 
                 RETURN_ERROR_IF(zc->staticSize, memory_allocation, "static cctx : no resize");
 
+                needsIndexReset = ZSTDirp_reset;
+
                 ZSTD_cwksp_free(ws, zc->customMem);
                 FORWARD_IF_ERROR(ZSTD_cwksp_create(ws, neededSpace, zc->customMem));
 
@@ -1500,7 +1510,7 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
             ws,
             &params.cParams,
             crp,
-            ZSTDirp_reset,
+            needsIndexReset,
             ZSTD_resetTarget_CCtx));
 
         /* ldm hash table */