Skip to content

std: slice.get(i) shouldn't do bounds check twice #13917

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

Closed
wants to merge 1 commit into from

Conversation

seanmonstar
Copy link
Contributor

The get function already checks that i is within bounds, so skip the
second one and use unsafe_ref.

The `get` function already checks that `i` is within bounds, so skip the
second one and use `unsafe_ref`.
@alexcrichton
Copy link
Member

Out of curiosity, did you see a performance improvement with this? LLVM may be good enough to realize the same condition is being checked twice (although I'm not sure).

@seanmonstar
Copy link
Contributor Author

Asking in IRC, I was told it does not, that's why I wrote this. However, trying some benches, with --opt-level=3, I'm getting 0ns/iter on both versions. May not be worth bothering with.

@alexcrichton
Copy link
Member

I looked at the generated assembly at -O, and there's only one bounds check, so it doesn't look like this actually buys us anything. In that case, closing for now.

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 13, 2023
Split out hir-def attribute handling parts into hir-expand

This should help with `cfg_attr` handling for macro inputs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants