]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Interleave Prefix and Dict Searches
authorW. Felix Handte <w@felixhandte.com>
Wed, 16 May 2018 19:20:16 +0000 (15:20 -0400)
committerW. Felix Handte <w@felixhandte.com>
Fri, 25 May 2018 17:13:57 +0000 (13:13 -0400)
lib/compress/zstd_double_fast.c

index de1529006a7a5b926803d5e639be757ef5cf9876..cf58da161199f8cbebabe2bee5aea666883e1ccc 100644 (file)
@@ -149,6 +149,20 @@ size_t ZSTD_compressBlock_doubleFast_generic(
             goto _match_found;
         }
 
+        /* check dictMatchState long match */
+        if (dictMode == ZSTD_dictMatchState) {
+            U32 const dictMatchIndexL = dictHashLong[h2];
+            const BYTE* dictMatchL = dictBase + dictMatchIndexL;
+            assert(dictMatchL < dictEnd);
+
+            if (dictMatchL > dictLowest && MEM_read64(dictMatchL) == MEM_read64(ip)) {
+                mLength = ZSTD_count_2segments(ip+8, dictMatchL+8, iend, dictEnd, prefixLowest) + 8;
+                offset = (U32)(current - dictMatchIndexL - dictIndexDelta);
+                while (((ip>anchor) & (dictMatchL>dictLowest)) && (ip[-1] == dictMatchL[-1])) { ip--; dictMatchL--; mLength++; } /* catch up */
+                goto _match_found;
+            }
+        }
+
         /* check prefix short match */
         if ( (matchIndexS > prefixLowestIndex) && (MEM_read32(match) == MEM_read32(ip)) ) {
             size_t const hl3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
@@ -170,22 +184,12 @@ size_t ZSTD_compressBlock_doubleFast_generic(
             goto _match_found;
         }
 
-        /* check dictMatchState matches */
+        /* check dictMatchState short match */
         if (dictMode == ZSTD_dictMatchState) {
-            U32 const dictMatchIndexL = dictHashLong[h2];
             U32 const dictMatchIndexS = dictHashSmall[h];
-            const BYTE* dictMatchL = dictBase + dictMatchIndexL;
             const BYTE* dictMatchS = dictBase + dictMatchIndexS;
-            assert(dictMatchL < dictEnd);
             assert(dictMatchS < dictEnd);
 
-            if (dictMatchL > dictLowest && MEM_read64(dictMatchL) == MEM_read64(ip)) {
-                mLength = ZSTD_count_2segments(ip+8, dictMatchL+8, iend, dictEnd, prefixLowest) + 8;
-                offset = (U32)(current - dictMatchIndexL - dictIndexDelta);
-                while (((ip>anchor) & (dictMatchL>dictLowest)) && (ip[-1] == dictMatchL[-1])) { ip--; dictMatchL--; mLength++; } /* catch up */
-                goto _match_found;
-            }
-
             if (dictMatchS > dictLowest && MEM_read32(dictMatchS) == MEM_read32(ip)) {
                 size_t const hl3 = ZSTD_hashPtr(ip+1, hBitsL, 8);
                 U32 const dictMatchIndexL3 = dictHashLong[hl3];