Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZSTD_fast_noDict: Avoid Safety Check When Writing ip1 into Table #3129

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix Comments Slightly
  • Loading branch information
felixhandte committed May 11, 2022
commit 1dd046a50783ebc4d0eb10928e71b2dd7c71cd4c
15 changes: 7 additions & 8 deletions lib/compress/zstd_fast.c
Original file line number Diff line number Diff line change
@@ -183,7 +183,9 @@ ZSTD_compressBlock_fast_noDict_generic(
offcode = REPCODE1_TO_OFFBASE;
mLength += 4;

/* first write next hash table entry; we've already calculated it */
/* First write next hash table entry; we've already calculated it.
* This write is known to be safe because the ip1 is before the
* repcode (ip2). */
hashTable[hash1] = (U32)(ip1 - base);

goto _match;
@@ -200,7 +202,9 @@ ZSTD_compressBlock_fast_noDict_generic(
if (MEM_read32(ip0) == mval) {
/* found a match! */

/* first write next hash table entry; we've already calculated it */
/* First write next hash table entry; we've already calculated it.
* This write is known to be safe because the ip1 == ip0 + 1, so
* we know we will resume searching after ip1 */
hashTable[hash1] = (U32)(ip1 - base);

goto _offset;
@@ -242,12 +246,7 @@ ZSTD_compressBlock_fast_noDict_generic(
* The minimum possible match has length 4, so the earliest ip0
* can be after we take this match will be the current ip0 + 4.
* ip1 is ip0 + step - 1. If ip1 is >= ip0 + 4, we can't safely
* write this position. The expedient thing to do is just to
* write a bad position.
*
* We perform this check here, separate from the write, because
* this is the only match path where this can occur. (In rep-
* code and the first match checks, ip1 == ip0 + 1.)
* write this position.
*/
hashTable[hash1] = (U32)(ip1 - base);
}