mirror of https://github.com/rust-lang/rust.git
This aligns the inline attributes of existing `__iterator_get_unchecked` with those of `next()` on adapters that have both.
It improves the performance of iterators using unchecked access when building in incremental mode (due to the larger CGU count?). It might negatively affect incremental compile times for better runtime results, but considering that the equivalent `next()` implementations also are `#[inline]` and usually are more complex this should be ok. ``` ./x.py bench library/core -i --stage 0 --test-args bench_trusted_random_access OLD: 119,172 ns/iter NEW: 17,714 ns/iter ```
This commit is contained in:
parent
e3db41bf97
commit
a68a5d219d
|
@ -129,6 +129,7 @@ where
|
|||
|
||||
#[rustc_inherit_overflow_checks]
|
||||
#[doc(hidden)]
|
||||
#[inline]
|
||||
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> <Self as Iterator>::Item
|
||||
where
|
||||
Self: TrustedRandomAccessNoCoerce,
|
||||
|
|
|
@ -125,6 +125,7 @@ where
|
|||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[inline]
|
||||
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> B
|
||||
where
|
||||
Self: TrustedRandomAccessNoCoerce,
|
||||
|
|
|
@ -554,6 +554,7 @@ pub unsafe trait TrustedRandomAccessNoCoerce: Sized {
|
|||
///
|
||||
/// Same requirements calling `get_unchecked` directly.
|
||||
#[doc(hidden)]
|
||||
#[inline]
|
||||
pub(in crate::iter::adapters) unsafe fn try_get_unchecked<I>(it: &mut I, idx: usize) -> I::Item
|
||||
where
|
||||
I: Iterator,
|
||||
|
@ -576,6 +577,7 @@ unsafe impl<I: Iterator> SpecTrustedRandomAccess for I {
|
|||
}
|
||||
|
||||
unsafe impl<I: Iterator + TrustedRandomAccessNoCoerce> SpecTrustedRandomAccess for I {
|
||||
#[inline]
|
||||
unsafe fn try_get_unchecked(&mut self, index: usize) -> Self::Item {
|
||||
// SAFETY: the caller must uphold the contract for
|
||||
// `Iterator::__iterator_get_unchecked`.
|
||||
|
|
|
@ -326,6 +326,7 @@ macro_rules! iterator {
|
|||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[inline]
|
||||
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
|
||||
// SAFETY: the caller must guarantee that `i` is in bounds of
|
||||
// the underlying slice, so `i` cannot overflow an `isize`, and
|
||||
|
|
Loading…
Reference in New Issue