- Notifications
You must be signed in to change notification settings - Fork 13.8k
Open
Labels
C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing such
Description
In this code:
fn binary_search_repro(needle: &str) -> Option<&str> { let haystack = &["a", "b"]; haystack.binary_search(&needle).ok().map(|i| haystack[i]) }
the compiler should be able to use the hint from slice::binary_search_by
in order to elide the length check in the index operation (haystack[i]
).
Seems the knowledge from this assert_unchecked
is lost somehow:
rust/library/core/src/slice/mod.rs
Line 2975 in e10aa88
unsafe { hint::assert_unchecked(base < self.len()) }; |
Godbolt: https://rust.godbolt.org/z/8zqq8vrrv
Metadata
Metadata
Assignees
Labels
C-optimizationCategory: An issue highlighting optimization opportunities or PRs implementing suchCategory: An issue highlighting optimization opportunities or PRs implementing such