Use map, sum in Subtree::coount instead of fold
This commit is contained in:
parent
d6d9aa2003
commit
ad1c3b5bd6
@ -153,11 +153,15 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
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