]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Remove long range matcher immediate repcode check 1021/head
authorNick Terrell <terrelln@fb.com>
Thu, 22 Feb 2018 03:30:05 +0000 (19:30 -0800)
committerNick Terrell <terrelln@fb.com>
Thu, 22 Feb 2018 23:18:47 +0000 (15:18 -0800)
The compression ratio gets about 0.01% worse on the files I tested, but the
code is much simpler.

lib/compress/zstd_ldm.c

index c18d68c8acb511ab760142bfe55136fcb18664f7..2c304b38bdc0ef2bbb18c00ac0047f3952bf8508 100644 (file)
@@ -514,14 +514,7 @@ size_t ZSTD_ldm_blockCompress(rawSeq const* sequences, size_t nbSeq,
 {
     ZSTD_blockCompressor const blockCompressor =
         ZSTD_selectBlockCompressor(cParams->strategy, extDict);
-    int const doImmediateRepCheck = cParams->strategy < ZSTD_btopt;
-    /* Prefix and extDict parameters */
-    U32 const dictLimit = ms->dictLimit;
-    U32 const lowestIndex = extDict ? ms->lowLimit : dictLimit;
     BYTE const* const base = ms->base;
-    BYTE const* const dictBase = extDict ? ms->dictBase : NULL;
-    BYTE const* const dictEnd = extDict ? dictBase + dictLimit : NULL;
-    BYTE const* const lowPrefixPtr = base + dictLimit;
     /* Input bounds */
     BYTE const* const istart = (BYTE const*)src;
     BYTE const* const iend = istart + srcSize;
@@ -558,69 +551,6 @@ size_t ZSTD_ldm_blockCompress(rawSeq const* sequences, size_t nbSeq,
                           sequence.matchLength - MINMATCH);
             ip += sequence.matchLength;
         }
-        /* Check immediate repcode */
-        if (doImmediateRepCheck) {
-            rawSeq* nextSeq = (seq + 1 < *nbSeq) ? &sequences[seq + 1] : NULL;
-            /* Allow repcodes up to the next predefined sequence */
-            BYTE const* const repCheckEnd = nextSeq
-                ? ip + nextSeq->litLength
-                : iend;
-            BYTE const* const repCheckLimit = repCheckEnd - HASH_READ_SIZE;
-
-            assert(repCheckEnd <= iend);
-
-            if (extDict) {
-              while (ip < repCheckLimit) {
-                  U32 const current = (U32)(ip-base);
-                  U32 const repIndex = current - rep[1];
-                  const BYTE* repMatch = repIndex < dictLimit ?
-                                          dictBase + repIndex : base + repIndex;
-                  if ( (((U32)((dictLimit-1) - repIndex) >= 3) &
-                              (repIndex > lowestIndex))  /* intentional overflow */
-                     && (MEM_read32(repMatch) == MEM_read32(ip)) ) {
-                      const BYTE* const repEnd = repIndex < dictLimit ?
-                                                  dictEnd : repCheckEnd;
-                      size_t const rLength = ZSTD_count_2segments(
-                          ip+4, repMatch+4, repCheckEnd, repEnd,
-                          lowPrefixPtr) + 4;
-                      /* Swap rep[1] <=> rep[0] */
-                      U32 const tmpOffset = rep[1];
-                      rep[1] = rep[0];
-                      rep[0] = tmpOffset;
-
-                      ZSTD_storeSeq(seqStore, 0, ip, 0, rLength-MINMATCH);
-                      ip += rLength;
-                      if (nextSeq) {
-                          assert(nextSeq->litLength >= rLength);
-                          nextSeq->litLength -= rLength;
-                      }
-                      continue;
-                  }
-                  break;
-              }
-            } else {
-                while ( (ip < repCheckLimit)
-                     && ( (rep[1] > 0) && (rep[1] <= (U32)(ip - lowPrefixPtr))
-                     && (MEM_read32(ip) == MEM_read32(ip - rep[1])) )) {
-
-                    size_t const rLength = ZSTD_count(ip+4, ip+4-rep[1],
-                                                      repCheckEnd) + 4;
-                    /* Swap rep[1] <=> rep[0] */
-                    {
-                        U32 const tmpOff = rep[1];
-                        rep[1] = rep[0];
-                        rep[0] = tmpOff;
-                    }
-
-                    ZSTD_storeSeq(seqStore, 0, ip, 0, rLength-MINMATCH);
-                    ip += rLength;
-                    if (nextSeq) {
-                        assert(nextSeq->litLength >= rLength);
-                        nextSeq->litLength -= rLength;
-                    }
-                }
-            }
-        }
     }
     ZSTD_ldm_limitTableUpdate(ms, ip);
     ZSTD_ldm_fillFastTables(ms, cParams, ip);