diff options
author | Edwin Cheng <[email protected]> | 2019-04-22 10:37:27 +0100 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2019-04-22 10:37:27 +0100 |
commit | ad1c3b5bd605942c85e4488b0483a0f50dc60942 (patch) | |
tree | 8da626b89a277722edd445798679339234596956 /crates/ra_tt/src | |
parent | d6d9aa20031be1179eec2158ea9c6017989cfae9 (diff) |
Use map, sum in Subtree::coount instead of fold
Diffstat (limited to 'crates/ra_tt/src')
-rw-r--r-- | crates/ra_tt/src/lib.rs | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs index 9cc646140..62c5ac52a 100644 --- a/crates/ra_tt/src/lib.rs +++ b/crates/ra_tt/src/lib.rs | |||
@@ -153,11 +153,15 @@ impl fmt::Display for Punct { | |||
153 | impl Subtree { | 153 | impl Subtree { |
154 | /// Count the number of tokens recursively | 154 | /// Count the number of tokens recursively |
155 | pub fn count(&self) -> usize { | 155 | pub fn count(&self) -> usize { |
156 | self.token_trees.iter().fold(self.token_trees.len(), |acc, c| { | 156 | let children_count = self |
157 | acc + match c { | 157 | .token_trees |
158 | .iter() | ||
159 | .map(|c| match c { | ||
158 | TokenTree::Subtree(c) => c.count(), | 160 | TokenTree::Subtree(c) => c.count(), |
159 | _ => 0, | 161 | _ => 0, |
160 | } | 162 | }) |
161 | }) | 163 | .sum::<usize>(); |
164 | |||
165 | self.token_trees.len() + children_count | ||
162 | } | 166 | } |
163 | } | 167 | } |