-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
feat(stdlib): Add String.lastIndexOf #1372
Conversation
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 what might be a bit better here is reusing the code from indexOf
. The only difference between the two would be the break
line in the loop.
You can turn indexOf
into a helper function that takes an additional argument, maybe called findFirst
, and then that if
becomes
if (Memory.compare(ptr, pptr, psize) == 0n) {
result = idx
if (findFirst) break
}
And then you can call the helper for both functions:
export let indexOf = (search, string) => {
indexOf(search, string, true)
}
export let lastIndexOf = (search, string) => {
indexOf(search, string, false)
}
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 left some suggestions here—I switched up the logic a bit to avoid a Memory.compare
when we're not at the start of a valid codepoint.
- Optimizes String.lastIndexOf todo checks only on whole codePoints - Undo Changes To GitIgnore
Co-authored-by: Oscar Spencer <oscar.spen@gmail.com>
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.
Great work!
Looks like you need to regenerate the Graindocs. |
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'm holding off my review until #1389 lands because this PR contains a bunch of formatting that shouldn't be included in the PR
GrainDoc Seems To Be Up To Date |
Co-authored-by: Blaine Bublitz <blaine.bublitz@gmail.com>
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.
Really cool! I like that you are diving into the low-level Grain stuff @spotandjake 🎉
Thank you, after working on my linker I have needed to work with a lot more low level grain stuff and realized it is actually quite friendly and easy to work with. |
This pr adds String.lastIndexOf, it works the same as indexOf but instead of returning the first occurance of the search it returns the last.