fix: take merge_offset into account when needle fits in a single chunk - #32
Merged
Merged
Conversation
TomAFrench
approved these changes
Jul 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem Resolved
Resolves https://github.com/noir-lang/noir-library-claude/issues/17
Summary of Changes
When a needle's length is less than the chunk's size (31) there's a final part of the code that copies from needle and haystck according to where inside the chunk we are. The logic worked when the needle matched exactly the beginning of the chunk but it didn't take into account that the needle be shifted with respect to the chunk start.
Son when comparing "ABCDEFGHIJKLMNOPQRSTUVWXYZ" vs. "BCE" it copied A, then BC but then incorrectly copied D instead of E (because of this offset mismatch) and then continued copying from haystack. Then the strings matches, incorrectly. When taking the merge offset into account we get "ABCEEFG..." so they don't match.
Note in the new code that when
merge_offsetis 0, we getlet predicate = (i >= 0) & (lhs_index < substring_length), which is what the old code was doing (i >= 0is always true) but when taking the offset into account we get a shift both in the current chunk's offset (i) as well as in the needle offset (lhs_index, the bytes we already copied from the needle).PR Checklist
cargo fmton default settings.