Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit f0210f8

Browse files
bors[bot]bellau
andauthored
11475: Impr mbe: remove unecessary temporary vec r=bellau a=bellau It's a micro optimization. I don't know if it's really necessary (less alloc is always better). Co-authored-by: bellau <[email protected]>
2 parents e5b6020 + ff4024e commit f0210f8

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

crates/mbe/src/expander/matcher.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -437,11 +437,12 @@ fn match_loop_inner<'t>(
437437
let mut new_item = item.clone();
438438
new_item.bindings = bindings_builder.copy(&new_item.bindings);
439439
new_item.dot.next();
440-
let mut vars = Vec::new();
441-
collect_vars(&mut vars, tokens);
442-
for var in vars {
443-
bindings_builder.push_empty(&mut new_item.bindings, &var);
444-
}
440+
collect_vars(
441+
&mut |s| {
442+
bindings_builder.push_empty(&mut new_item.bindings, &s);
443+
},
444+
tokens,
445+
);
445446
cur_items.push(new_item);
446447
}
447448
cur_items.push(MatchState {
@@ -729,17 +730,16 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult<Option<Fragmen
729730
input.expect_fragment(fragment).map(|it| it.map(Fragment::Tokens))
730731
}
731732

732-
fn collect_vars(buf: &mut Vec<SmolStr>, pattern: &MetaTemplate) {
733+
fn collect_vars(collector_fun: &mut impl FnMut(SmolStr), pattern: &MetaTemplate) {
733734
for op in pattern.iter() {
734735
match op {
735-
Op::Var { name, .. } => buf.push(name.clone()),
736+
Op::Var { name, .. } => collector_fun(name.clone()),
736737
Op::Leaf(_) => (),
737-
Op::Subtree { tokens, .. } => collect_vars(buf, tokens),
738-
Op::Repeat { tokens, .. } => collect_vars(buf, tokens),
738+
Op::Subtree { tokens, .. } => collect_vars(collector_fun, tokens),
739+
Op::Repeat { tokens, .. } => collect_vars(collector_fun, tokens),
739740
}
740741
}
741742
}
742-
743743
impl MetaTemplate {
744744
fn iter_delimited<'a>(&'a self, delimited: Option<&'a tt::Delimiter>) -> OpDelimitedIter<'a> {
745745
OpDelimitedIter { inner: &self.0, idx: 0, delimited }

0 commit comments

Comments
 (0)