Skip to content

Commit 9d95cab

Browse files
committed
Optimize punctuated::fold
1 parent 82ffe86 commit 9d95cab

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/punctuated.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,13 +1083,17 @@ where
10831083
V: ?Sized,
10841084
F: FnMut(&mut V, T) -> T,
10851085
{
1086-
punctuated
1087-
.into_pairs()
1088-
.map(|pair| match pair {
1089-
Pair::Punctuated(t, p) => Pair::Punctuated(f(fold, t), p),
1090-
Pair::End(t) => Pair::End(f(fold, t)),
1091-
})
1092-
.collect()
1086+
Punctuated {
1087+
inner: punctuated
1088+
.inner
1089+
.into_iter()
1090+
.map(|(t, p)| (f(fold, t), p))
1091+
.collect(),
1092+
last: match punctuated.last {
1093+
Some(t) => Some(Box::new(f(fold, *t))),
1094+
None => None,
1095+
},
1096+
}
10931097
}
10941098

10951099
#[cfg(feature = "printing")]

0 commit comments

Comments
 (0)