diff options
| author | The 8472 <git@infinite-source.de> | 2023-09-02 13:37:00 +0200 |
|---|---|---|
| committer | The 8472 <git@infinite-source.de> | 2023-10-06 18:33:25 +0200 |
| commit | b018ad3d41de500c52156fb8a84d2197d966f370 (patch) | |
| tree | 8ec9db8877cd7317f5cc6a2fbef85124e8c2588a /library/core/src/array | |
| parent | 6683f13fa1ba91ab84dd5bc5bc21965a1b0530e1 (diff) | |
| download | rust-b018ad3d41de500c52156fb8a84d2197d966f370.tar.gz rust-b018ad3d41de500c52156fb8a84d2197d966f370.zip | |
optimize zipping over array iterators
Diffstat (limited to 'library/core/src/array')
| -rw-r--r-- | library/core/src/array/iter.rs | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/library/core/src/array/iter.rs b/library/core/src/array/iter.rs index 587877dff55..56ba12c4636 100644 --- a/library/core/src/array/iter.rs +++ b/library/core/src/array/iter.rs @@ -4,7 +4,7 @@ use crate::num::NonZeroUsize; use crate::{ fmt, intrinsics::transmute_unchecked, - iter::{self, ExactSizeIterator, FusedIterator, TrustedLen}, + iter::{self, ExactSizeIterator, FusedIterator, TrustedLen, TrustedRandomAccessNoCoerce}, mem::MaybeUninit, ops::{IndexRange, Range}, ptr, @@ -293,6 +293,12 @@ impl<T, const N: usize> Iterator for IntoIter<T, N> { NonZeroUsize::new(remaining).map_or(Ok(()), Err) } + + #[inline] + unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item { + // SAFETY: The caller must provide an idx that is in bound of the remainder. + unsafe { self.data.as_ptr().add(self.alive.start()).add(idx).cast::<T>().read() } + } } #[stable(feature = "array_value_iter_impls", since = "1.40.0")] @@ -374,6 +380,25 @@ impl<T, const N: usize> FusedIterator for IntoIter<T, N> {} #[stable(feature = "array_value_iter_impls", since = "1.40.0")] unsafe impl<T, const N: usize> TrustedLen for IntoIter<T, N> {} +#[doc(hidden)] +#[unstable(issue = "none", feature = "std_internals")] +#[rustc_unsafe_specialization_marker] +pub trait NonDrop {} + +// T: Copy as approximation for !Drop since get_unchecked does not advance self.alive +// and thus we can't implement drop-handling +#[unstable(issue = "none", feature = "std_internals")] +impl<T: Copy> NonDrop for T {} + +#[doc(hidden)] +#[unstable(issue = "none", feature = "std_internals")] +unsafe impl<T, const N: usize> TrustedRandomAccessNoCoerce for IntoIter<T, N> +where + T: NonDrop, +{ + const MAY_HAVE_SIDE_EFFECT: bool = false; +} + #[stable(feature = "array_value_iter_impls", since = "1.40.0")] impl<T: Clone, const N: usize> Clone for IntoIter<T, N> { fn clone(&self) -> Self { |
