Skip to content

Commit

Permalink
Optimize punctuated::fold
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed May 19, 2024
1 parent 82ffe86 commit 9d95cab
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/punctuated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1083,13 +1083,17 @@ where
V: ?Sized,
F: FnMut(&mut V, T) -> T,
{
punctuated
.into_pairs()
.map(|pair| match pair {
Pair::Punctuated(t, p) => Pair::Punctuated(f(fold, t), p),
Pair::End(t) => Pair::End(f(fold, t)),
})
.collect()
Punctuated {
inner: punctuated
.inner
.into_iter()
.map(|(t, p)| (f(fold, t), p))
.collect(),
last: match punctuated.last {
Some(t) => Some(Box::new(f(fold, *t))),
None => None,
},
}
}

#[cfg(feature = "printing")]
Expand Down

0 comments on commit 9d95cab

Please sign in to comment.