summaryrefslogtreecommitdiffstats
path: root/library/core/src/iter/adapters/array_chunks.rs
diff options
context:
space:
mode:
Diffstat (limited to 'library/core/src/iter/adapters/array_chunks.rs')
-rw-r--r--library/core/src/iter/adapters/array_chunks.rs20
1 files changed, 6 insertions, 14 deletions
diff --git a/library/core/src/iter/adapters/array_chunks.rs b/library/core/src/iter/adapters/array_chunks.rs
index 5e4211058..13719c727 100644
--- a/library/core/src/iter/adapters/array_chunks.rs
+++ b/library/core/src/iter/adapters/array_chunks.rs
@@ -1,7 +1,5 @@
use crate::array;
-use crate::const_closure::ConstFnMutClosure;
use crate::iter::{ByRefSized, FusedIterator, Iterator, TrustedRandomAccessNoCoerce};
-use crate::mem::{self, MaybeUninit};
use crate::ops::{ControlFlow, NeverShortCircuit, Try};
/// An iterator over `N` elements of the iterator at a time.
@@ -189,13 +187,12 @@ where
I: Iterator,
{
#[inline]
- default fn fold<B, F>(mut self, init: B, mut f: F) -> B
+ default fn fold<B, F>(mut self, init: B, f: F) -> B
where
Self: Sized,
F: FnMut(B, Self::Item) -> B,
{
- let fold = ConstFnMutClosure::new(&mut f, NeverShortCircuit::wrap_mut_2_imp);
- self.try_fold(init, fold).0
+ self.try_fold(init, NeverShortCircuit::wrap_mut_2(f)).0
}
}
@@ -214,19 +211,14 @@ where
let mut i = 0;
// Use a while loop because (0..len).step_by(N) doesn't optimize well.
while inner_len - i >= N {
- let mut chunk = MaybeUninit::uninit_array();
- let mut guard = array::Guard { array_mut: &mut chunk, initialized: 0 };
- while guard.initialized < N {
+ let chunk = crate::array::from_fn(|local| {
// SAFETY: The method consumes the iterator and the loop condition ensures that
// all accesses are in bounds and only happen once.
unsafe {
- let idx = i + guard.initialized;
- guard.push_unchecked(self.iter.__iterator_get_unchecked(idx));
+ let idx = i + local;
+ self.iter.__iterator_get_unchecked(idx)
}
- }
- mem::forget(guard);
- // SAFETY: The loop above initialized all elements
- let chunk = unsafe { MaybeUninit::array_assume_init(chunk) };
+ });
accum = f(accum, chunk);
i += N;
}