Skip to content

Commit e1bc368

Browse files
committed
Rewrite Iterator::unzip in terms of (A, B)::extend
1 parent 871589c commit e1bc368

File tree

1 file changed

+3
-22
lines changed

1 file changed

+3
-22
lines changed

core/src/iter/traits/iterator.rs

+3-22
Original file line numberDiff line numberDiff line change
@@ -2819,28 +2819,9 @@ pub trait Iterator {
28192819
FromB: Default + Extend<B>,
28202820
Self: Sized + Iterator<Item = (A, B)>,
28212821
{
2822-
fn extend<'a, A, B>(
2823-
ts: &'a mut impl Extend<A>,
2824-
us: &'a mut impl Extend<B>,
2825-
) -> impl FnMut((), (A, B)) + 'a {
2826-
move |(), (t, u)| {
2827-
ts.extend_one(t);
2828-
us.extend_one(u);
2829-
}
2830-
}
2831-
2832-
let mut ts: FromA = Default::default();
2833-
let mut us: FromB = Default::default();
2834-
2835-
let (lower_bound, _) = self.size_hint();
2836-
if lower_bound > 0 {
2837-
ts.extend_reserve(lower_bound);
2838-
us.extend_reserve(lower_bound);
2839-
}
2840-
2841-
self.fold((), extend(&mut ts, &mut us));
2842-
2843-
(ts, us)
2822+
let mut unzipped: (FromA, FromB) = Default::default();
2823+
unzipped.extend(self);
2824+
unzipped
28442825
}
28452826

28462827
/// Creates an iterator which copies all of its elements.

0 commit comments

Comments
 (0)