]> git.ipfire.org Git - thirdparty/zstd.git/commitdiff
Add comments to ZSTD_getLowest{Match,Prefix}Index() 2338/head
authorNick Terrell <terrelln@fb.com>
Thu, 1 Oct 2020 20:21:46 +0000 (13:21 -0700)
committerNick Terrell <terrelln@fb.com>
Thu, 1 Oct 2020 20:21:46 +0000 (13:21 -0700)
Clarify how we handle dictionaries in each case.

lib/compress/zstd_compress_internal.h

index 361e917545d9152224bcd4183dc594d05951fd82..728afade7a5ef2e99309bf85f66f1c0f72201f7b 100644 (file)
@@ -1001,6 +1001,10 @@ MEM_STATIC U32 ZSTD_getLowestMatchIndex(const ZSTD_matchState_t* ms, U32 curr, u
     U32    const lowestValid = ms->window.lowLimit;
     U32    const withinWindow = (curr - lowestValid > maxDistance) ? curr - maxDistance : lowestValid;
     U32    const isDictionary = (ms->loadedDictEnd != 0);
+    /* When using a dictionary the entire dictionary is valid if a single byte of the dictionary
+     * is within the window. We invalidate the dictionary (and set loadedDictEnd to 0) when it isn't
+     * valid for the entire block. So this check is sufficient to find the lowest valid match index.
+     */
     U32    const matchLowest = isDictionary ? lowestValid : withinWindow;
     return matchLowest;
 }
@@ -1014,6 +1018,9 @@ MEM_STATIC U32 ZSTD_getLowestPrefixIndex(const ZSTD_matchState_t* ms, U32 curr,
     U32    const lowestValid = ms->window.dictLimit;
     U32    const withinWindow = (curr - lowestValid > maxDistance) ? curr - maxDistance : lowestValid;
     U32    const isDictionary = (ms->loadedDictEnd != 0);
+    /* When computing the lowest prefix index we need to take the dictionary into account to handle
+     * the edge case where the dictionary and the source are contiguous in memory.
+     */
     U32    const matchLowest = isDictionary ? lowestValid : withinWindow;
     return matchLowest;
 }