Skip to content

Commit a68a5d2

Browse files
committed
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 ```
1 parent e3db41b commit a68a5d2

File tree

4 files changed

+5
-0
lines changed

4 files changed

+5
-0
lines changed

library/core/src/iter/adapters/enumerate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ where
129129

130130
#[rustc_inherit_overflow_checks]
131131
#[doc(hidden)]
132+
#[inline]
132133
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> <Self as Iterator>::Item
133134
where
134135
Self: TrustedRandomAccessNoCoerce,

library/core/src/iter/adapters/map.rs

+1
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ where
125125
}
126126

127127
#[doc(hidden)]
128+
#[inline]
128129
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> B
129130
where
130131
Self: TrustedRandomAccessNoCoerce,

library/core/src/iter/adapters/zip.rs

+2
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,7 @@ pub unsafe trait TrustedRandomAccessNoCoerce: Sized {
554554
///
555555
/// Same requirements calling `get_unchecked` directly.
556556
#[doc(hidden)]
557+
#[inline]
557558
pub(in crate::iter::adapters) unsafe fn try_get_unchecked<I>(it: &mut I, idx: usize) -> I::Item
558559
where
559560
I: Iterator,
@@ -576,6 +577,7 @@ unsafe impl<I: Iterator> SpecTrustedRandomAccess for I {
576577
}
577578

578579
unsafe impl<I: Iterator + TrustedRandomAccessNoCoerce> SpecTrustedRandomAccess for I {
580+
#[inline]
579581
unsafe fn try_get_unchecked(&mut self, index: usize) -> Self::Item {
580582
// SAFETY: the caller must uphold the contract for
581583
// `Iterator::__iterator_get_unchecked`.

library/core/src/slice/iter/macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ macro_rules! iterator {
326326
}
327327

328328
#[doc(hidden)]
329+
#[inline]
329330
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
330331
// SAFETY: the caller must guarantee that `i` is in bounds of
331332
// the underlying slice, so `i` cannot overflow an `isize`, and

0 commit comments

Comments
 (0)