-
Notifications
You must be signed in to change notification settings - Fork 84
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
get_unchecked
isn't unchecked
#74
base: master
Are you sure you want to change the base?
Conversation
This can be seen in the assembly generated by the `get_unchecked` function. Although there is no bounds checking on the array, it still checks whether the entry is occupied and so there is a branch and panic handling code due to the use of `unreachable!()`. I think that logically, both kinds of checking are the same type of error (you accessed an invalid index), so it makes sense for `get_unchecked` to do no branches at all, only address arithmetic. The only open question is whether the documentation should be adjusted to use a term other than "bounds checking" here since the set of valid slab indices is not an interval.
This comment has been minimized.
This comment has been minimized.
On second thought, I think the addition of safety requirements like this should actually be considered a breaking change. |
I think the addition of safety requirements like this should actually be considered a breaking change.
We could elide this check by replacing the |
This code (in the PR) has the same performance as the |
I added the documentation change from #40 (comment) to improve the terminology from "bounds checking". But unlike the author of that comment, I do think this PR is worth merging, even if it is a breaking change requiring a semver bump. |
If there are other breaking changes, I'm okay with releasing this and them together, but I don't want to bump the major version just for this optimization. |
Okay, I'm not the maintainer so do what you think is best. That said, I imagine that breaking changes to a crate like this don't happen very often, so that stance might delay it for a long time. |
I agree that this is likely to delay. However, slab is widely used so I want to avoid major version bumps as much as possible. |
This can be seen in the assembly generated by the
get_unchecked
function. Although there is no bounds checking on the array, it still checks whether the entry is occupied and so there is a branch and panic handling code due to the use ofunreachable!()
. I think that logically, both kinds of checking are the same type of error (you accessed an invalid index), so it makes sense forget_unchecked
to do no branches at all, only address arithmetic.The only open question is whether the documentation should be adjusted to use a term other than "bounds checking" here since the set of valid slab indices is not an interval.