-
Notifications
You must be signed in to change notification settings - Fork 126
improve StringView::find
and StringView::rev_find
#2201
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
base: main
Are you sure you want to change the base?
Conversation
Inconsistent empty needle handling between find and rev_find functionsCategory Skip table creation uses bitwise masking that may cause hash collisionsCategory Code duplication between forward and reverse Boyer-Moore-Horspool implementationsCategory |
Pull Request Test Coverage Report for Build 408Details
💛 - Coveralls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Reverse Search Skip Table Logic Error
The boyer_moore_horspool_rev_find
function's skip table is incorrectly constructed and used. It applies forward Boyer-Moore-Horspool skip table logic (storing i
as the skip value) and uses the first character of the current window (haystack.unsafe_charcode_at(i)
) for lookup, which is unsuitable for a reverse search. This leads to incorrect and inefficient skipping behavior.
string/methods.mbt#L200-L207
Lines 200 to 207 in 041feb6
guard haystack_len >= needle_len else { return None } | |
let skip_table = FixedArray::make(1 << 8, needle_len) | |
for i = needle_len - 1; i > 0; i = i - 1 { | |
skip_table[needle.unsafe_charcode_at(i) & 0xFF] = i | |
} | |
for i = haystack_len - needle_len | |
i >= 0 | |
i = i - skip_table[haystack.unsafe_charcode_at(i) & 0xFF] { |
BugBot free trial expires on July 22, 2025
Learn more in the Cursor dashboard.
Was this report helpful? Give feedback by reacting with 👍 or 👎
Bench code
Bench result