]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Simplify Match Limit Checks
authorW. Felix Handte <w@felixhandte.com>
Fri, 4 Sep 2020 04:31:00 +0000 (00:31 -0400)
committerW. Felix Handte <w@felixhandte.com>
Fri, 11 Sep 2020 02:10:02 +0000 (22:10 -0400)
Seems like a ~1.25% speedup.

lib/compress/zstd_lazy.c

index efe58b3cd98b2f97bce4df21e0117b1f02253eec..898f1c21f75afa8926f1a84e9ad78d0cd87657a3 100644 (file)
@@ -535,8 +535,7 @@ void ZSTD_dedicatedDictSearch_lazy_loadDictionary(ZSTD_matchState_t* ms, const B
             if (count == cacheSize) {
                 for (count = 0; count < chainLimit;) {
                     if (i < minChain) {
-                        countBeyondMinChain++;
-                        if (countBeyondMinChain > cacheSize) {
+                        if (!i || countBeyondMinChain++ > cacheSize) {
                             /* only allow pulling `cacheSize` number of entries
                              * into the cache or chainTable beyond `minChain`,
                              * to replace the entries pulled out of the
@@ -688,10 +687,13 @@ size_t ZSTD_HcFindBestMatch_generic (
             matchIndex = dms->hashTable[ddsIdx + ddsAttempt];
             match = ddsBase + matchIndex;
 
-            if (matchIndex < ddsLowestIndex) {
+            if (!matchIndex) {
                 return ml;
             }
 
+            /* guaranteed by table construction */
+            (void)ddsLowestIndex;
+            assert(matchIndex >= ddsLowestIndex);
             assert(match+4 <= ddsEnd);
             if (MEM_read32(match) == MEM_read32(ip)) {
                 /* assumption : matchIndex <= dictLimit-4 (by table construction) */
@@ -727,10 +729,8 @@ size_t ZSTD_HcFindBestMatch_generic (
                 matchIndex = dms->chainTable[chainIndex];
                 match = ddsBase + matchIndex;
 
-                if (matchIndex < ddsLowestIndex) {
-                    break;
-                }
-
+                /* guaranteed by table construction */
+                assert(matchIndex >= ddsLowestIndex);
                 assert(match+4 <= ddsEnd);
                 if (MEM_read32(match) == MEM_read32(ip)) {
                     /* assumption : matchIndex <= dictLimit-4 (by table construction) */