]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
fixed: tree not updated after finding very long rep matches
authorinikep <inikep@gmail.com>
Tue, 9 Aug 2016 09:03:15 +0000 (11:03 +0200)
committerinikep <inikep@gmail.com>
Tue, 9 Aug 2016 09:03:15 +0000 (11:03 +0200)
lib/compress/zstd_compress.c
lib/compress/zstd_opt.h

index 56c63601ed6b626fd9a1057168bbbb5dd095e3ec..a496317cb3c99c88939ac6be1f9b884dd530fd5a 100644 (file)
@@ -2205,8 +2205,13 @@ static ZSTD_blockCompressor ZSTD_selectBlockCompressor(ZSTD_strategy strat, int
 static size_t ZSTD_compressBlock_internal(ZSTD_CCtx* zc, void* dst, size_t dstCapacity, const void* src, size_t srcSize)
 {
     ZSTD_blockCompressor const blockCompressor = ZSTD_selectBlockCompressor(zc->params.cParams.strategy, zc->lowLimit < zc->dictLimit);
+    const BYTE* const base = zc->base;
+    const BYTE* const istart = (const BYTE*)src;
+    const U32 current = (U32)(istart-base);
     if (srcSize < MIN_CBLOCK_SIZE+ZSTD_blockHeaderSize+1) return 0;   /* don't even attempt compression below a certain srcSize */
     ZSTD_resetSeqStore(&(zc->seqStore));
+    if (current > zc->nextToUpdate + 384)
+        zc->nextToUpdate = current - MIN(192, (U32)(current - zc->nextToUpdate - 384));   /* update tree not updated after finding very long rep matches */
     blockCompressor(zc, src, srcSize);
     return ZSTD_compressSequences(zc, dst, dstCapacity, srcSize);
 }
index d9f6cfdc185d2ad0aeedc44d260fc6291eef9c66..f30cdbfda17e9e8f5ebb146ba4ef5d1c00dad57b 100644 (file)
@@ -674,8 +674,8 @@ _storeSequence:   /* cur, last_pos, best_mlen, best_off have to be set */
 
 #if ZSTD_OPT_DEBUG >= 5
             U32 ml2;
-            if (offset > ZSTD_REP_MOVE_OPT)
-                ml2 = (U32)ZSTD_count(ip, ip-(offset-ZSTD_REP_MOVE_OPT), iend);
+            if (offset+1 > ZSTD_REP_MOVE_OPT)
+                ml2 = (U32)ZSTD_count(ip, ip-(offset+1-ZSTD_REP_MOVE_OPT), iend);
             else
                 ml2 = (U32)ZSTD_count(ip, ip-rep[0], iend);
             if ((offset >= 8) && (ml2 < mlen || ml2 < minMatch)) {
@@ -992,8 +992,8 @@ _storeSequence:   /* cur, last_pos, best_mlen, best_off have to be set */
 
 #if ZSTD_OPT_DEBUG >= 5
             U32 ml2;
-            if (offset > ZSTD_REP_MOVE_OPT) {
-                best_off = offset - ZSTD_REP_MOVE_OPT;
+            if (offset+1 > ZSTD_REP_MOVE_OPT) {
+                best_off = offset+1 - ZSTD_REP_MOVE_OPT;
                 if (best_off > (size_t)(ip - prefixStart))  {
                     const BYTE* match = dictEnd - (best_off - (ip - prefixStart));
                     ml2 = ZSTD_count_2segments(ip, match, iend, dictEnd, prefixStart);