We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 72b01d5 commit 07a1d5fCopy full SHA for 07a1d5f
library/core/src/iter/adapters/take.rs
@@ -303,13 +303,12 @@ impl<I: Iterator + TrustedRandomAccess> SpecTake for Take<I> {
303
}
304
305
#[inline]
306
- fn spec_for_each<F: FnMut(Self::Item)>(self, f: F) {
307
- // Based on the the Iterator trait default impl.
308
- #[inline]
309
- fn call<T>(mut f: impl FnMut(T)) -> impl FnMut((), T) {
310
- move |(), item| f(item)
+ fn spec_for_each<F: FnMut(Self::Item)>(mut self, mut f: F) {
+ let end = self.n.min(self.iter.size());
+ for i in 0..end {
+ // SAFETY: i < end <= self.iter.size() and we discard the iterator at the end
+ let val = unsafe { self.iter.__iterator_get_unchecked(i) };
311
+ f(val);
312
-
313
- self.spec_fold((), call(f));
314
315
0 commit comments