-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
String: implement Rabin-Karp algorithm for #byte_index #4609
String: implement Rabin-Karp algorithm for #byte_index #4609
Conversation
pointer += 1 | ||
end | ||
|
||
while true |
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.
Maybe use loop do
?
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.
loop do; end
is expanded to: i = 0; while true; i += 1; end
. I'm not sure variable i
is eliminated by LLVM anytime.
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.
Be sure.
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.
It's a single unused integer local variable, i think it'd be very very unlikely for LLVM to keep it around. You should check for yourself though.
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.
git grep 'while true' | wc -l
yields 149
, so I think all while true
should be replaced to loop
if this was fixed. I would like to keep while true
for now.
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.
I think while true is fine but I was just pointing out that in a release build there's no difference in performance.
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.
So I want to keep it for merging this quickly because I believe this fix is good enogh. We can discuss about loop do
optimization after it.
ping. I believe this is ready to be merged. |
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.
Looks good.
Thank you very much! |
@asterite My tomorrow comes after five months! (#3876 (comment)) Sorry.
Benchmark is here: https://gist.github.com/MakeNowJust/363ae118b266e77e576a828acaad59a0
And my result:
String#index
: #3873String#rindex
: #3876