Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions library/core/src/array/iter/iter_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ impl<T> PartialDrop for [MaybeUninit<T>] {
}
}
impl<T, const N: usize> PartialDrop for [MaybeUninit<T>; N] {
#[inline]
unsafe fn partial_drop(&mut self, alive: IndexRange) {
let slice: &mut [MaybeUninit<T>] = self;
// SAFETY: Initialized elements in the array are also initialized in the slice.
Expand Down Expand Up @@ -124,7 +125,6 @@ impl<T: Clone, const N: usize> Clone for PolymorphicIter<[MaybeUninit<T>; N]> {
}

impl<T> PolymorphicIter<[MaybeUninit<T>]> {
#[inline]
pub(super) fn as_slice(&self) -> &[T] {
// SAFETY: We know that all elements within `alive` are properly initialized.
unsafe {
Expand All @@ -133,7 +133,6 @@ impl<T> PolymorphicIter<[MaybeUninit<T>]> {
}
}

#[inline]
pub(super) fn as_mut_slice(&mut self) -> &mut [T] {
// SAFETY: We know that all elements within `alive` are properly initialized.
unsafe {
Expand All @@ -157,7 +156,6 @@ impl<T: fmt::Debug> fmt::Debug for PolymorphicIter<[MaybeUninit<T>]> {
/// We don't implement the actual iterator traits because we want to implement
/// things like `try_fold` that require `Self: Sized` (which we're not).
impl<T> PolymorphicIter<[MaybeUninit<T>]> {
#[inline]
pub(super) fn next(&mut self) -> Option<T> {
// Get the next index from the front.
//
Expand All @@ -175,13 +173,11 @@ impl<T> PolymorphicIter<[MaybeUninit<T>]> {
})
}

#[inline]
pub(super) fn size_hint(&self) -> (usize, Option<usize>) {
let len = self.len();
(len, Some(len))
}

#[inline]
pub(super) fn advance_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
// This also moves the start, which marks them as conceptually "dropped",
// so if anything goes bad then our drop impl won't double-free them.
Expand All @@ -197,12 +193,10 @@ impl<T> PolymorphicIter<[MaybeUninit<T>]> {
NonZero::new(remaining).map_or(Ok(()), Err)
}

#[inline]
pub(super) fn fold<B>(&mut self, init: B, f: impl FnMut(B, T) -> B) -> B {
self.try_fold(init, NeverShortCircuit::wrap_mut_2(f)).0
}

#[inline]
pub(super) fn try_fold<B, F, R>(&mut self, init: B, mut f: F) -> R
where
F: FnMut(B, T) -> R,
Expand All @@ -221,7 +215,6 @@ impl<T> PolymorphicIter<[MaybeUninit<T>]> {
})
}

#[inline]
pub(super) fn next_back(&mut self) -> Option<T> {
// Get the next index from the back.
//
Expand All @@ -239,7 +232,6 @@ impl<T> PolymorphicIter<[MaybeUninit<T>]> {
})
}

#[inline]
pub(super) fn advance_back_by(&mut self, n: usize) -> Result<(), NonZero<usize>> {
// This also moves the end, which marks them as conceptually "dropped",
// so if anything goes bad then our drop impl won't double-free them.
Expand All @@ -255,12 +247,10 @@ impl<T> PolymorphicIter<[MaybeUninit<T>]> {
NonZero::new(remaining).map_or(Ok(()), Err)
}

#[inline]
pub(super) fn rfold<B>(&mut self, init: B, f: impl FnMut(B, T) -> B) -> B {
self.try_rfold(init, NeverShortCircuit::wrap_mut_2(f)).0
}

#[inline]
pub(super) fn try_rfold<B, F, R>(&mut self, init: B, mut f: F) -> R
where
F: FnMut(B, T) -> R,
Expand Down
Loading