mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-21 11:23:03 +00:00
Use map, sum in Subtree::coount instead of fold
This commit is contained in:
parent
d6d9aa2003
commit
ad1c3b5bd6
@ -153,11 +153,15 @@ impl fmt::Display for Punct {
|
||||
impl Subtree {
|
||||
/// Count the number of tokens recursively
|
||||
pub fn count(&self) -> usize {
|
||||
self.token_trees.iter().fold(self.token_trees.len(), |acc, c| {
|
||||
acc + match c {
|
||||
let children_count = self
|
||||
.token_trees
|
||||
.iter()
|
||||
.map(|c| match c {
|
||||
TokenTree::Subtree(c) => c.count(),
|
||||
_ => 0,
|
||||
}
|
||||
})
|
||||
})
|
||||
.sum::<usize>();
|
||||
|
||||
self.token_trees.len() + children_count
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user