From ff4024eebd86c471a9f07f1c90288facb35a3a5a Mon Sep 17 00:00:00 2001 From: bellau Date: Mon, 14 Feb 2022 21:06:13 +0100 Subject: [PATCH] Impr mbe: remove unecessary temporary vec --- crates/mbe/src/expander/matcher.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/mbe/src/expander/matcher.rs b/crates/mbe/src/expander/matcher.rs index c5c555e302..b4c6d3bf61 100644 --- a/crates/mbe/src/expander/matcher.rs +++ b/crates/mbe/src/expander/matcher.rs @@ -437,11 +437,12 @@ fn match_loop_inner<'t>( let mut new_item = item.clone(); new_item.bindings = bindings_builder.copy(&new_item.bindings); new_item.dot.next(); - let mut vars = Vec::new(); - collect_vars(&mut vars, tokens); - for var in vars { - bindings_builder.push_empty(&mut new_item.bindings, &var); - } + collect_vars( + &mut |s| { + bindings_builder.push_empty(&mut new_item.bindings, &s); + }, + tokens, + ); cur_items.push(new_item); } cur_items.push(MatchState { @@ -729,17 +730,16 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult, pattern: &MetaTemplate) { +fn collect_vars(collector_fun: &mut impl FnMut(SmolStr), pattern: &MetaTemplate) { for op in pattern.iter() { match op { - Op::Var { name, .. } => buf.push(name.clone()), + Op::Var { name, .. } => collector_fun(name.clone()), Op::Leaf(_) => (), - Op::Subtree { tokens, .. } => collect_vars(buf, tokens), - Op::Repeat { tokens, .. } => collect_vars(buf, tokens), + Op::Subtree { tokens, .. } => collect_vars(collector_fun, tokens), + Op::Repeat { tokens, .. } => collect_vars(collector_fun, tokens), } } } - impl MetaTemplate { fn iter_delimited<'a>(&'a self, delimited: Option<&'a tt::Delimiter>) -> OpDelimitedIter<'a> { OpDelimitedIter { inner: &self.0, idx: 0, delimited }