-
Notifications
You must be signed in to change notification settings - Fork 919
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
Replace ndpi_strnstr() implementation with an optimal one #2447
Conversation
03d16ff
to
eeb4569
Compare
@0xA50C1A1 |
Yea, I did. At worst the performance is on par with the old implementation, at best it can be 8 times faster. |
Worst case:
Best case:
|
|
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.
Thank you!
Please sign (check) the below before submitting the Pull Request:
#2433 #2439
Describe changes:
I apologize for the buggy implementation I suggested last time. This time, I simply took the already quite optimal
ndpi_memmem()
code and reworked it to handle null-terminated strings. This implementation shows better results in the benchmark, even with thestrlen
andstrnlen
calls inside. I've thoroughly tested it, and your unit tests are passing correctly.Main changes:
memchr
to quickly locate the first character of theneedle
substring within thehaystack
. This avoids unnecessary character comparisons, leading to better performance, especially for long strings.haystack
is shorter thanneedle
, then there's no point in doing unnecessary comparisons.@IvanNardi @utoni what do you think, guys?