Merge #11475
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 <laurent.belmonte@gmail.com>
This commit is contained in:
commit
f0210f8a43
@ -437,11 +437,12 @@ macro_rules! try_push {
|
|||||||
let mut new_item = item.clone();
|
let mut new_item = item.clone();
|
||||||
new_item.bindings = bindings_builder.copy(&new_item.bindings);
|
new_item.bindings = bindings_builder.copy(&new_item.bindings);
|
||||||
new_item.dot.next();
|
new_item.dot.next();
|
||||||
let mut vars = Vec::new();
|
collect_vars(
|
||||||
collect_vars(&mut vars, tokens);
|
&mut |s| {
|
||||||
for var in vars {
|
bindings_builder.push_empty(&mut new_item.bindings, &s);
|
||||||
bindings_builder.push_empty(&mut new_item.bindings, &var);
|
},
|
||||||
}
|
tokens,
|
||||||
|
);
|
||||||
cur_items.push(new_item);
|
cur_items.push(new_item);
|
||||||
}
|
}
|
||||||
cur_items.push(MatchState {
|
cur_items.push(MatchState {
|
||||||
@ -729,17 +730,16 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult<Option<Fragmen
|
|||||||
input.expect_fragment(fragment).map(|it| it.map(Fragment::Tokens))
|
input.expect_fragment(fragment).map(|it| it.map(Fragment::Tokens))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn collect_vars(buf: &mut Vec<SmolStr>, pattern: &MetaTemplate) {
|
fn collect_vars(collector_fun: &mut impl FnMut(SmolStr), pattern: &MetaTemplate) {
|
||||||
for op in pattern.iter() {
|
for op in pattern.iter() {
|
||||||
match op {
|
match op {
|
||||||
Op::Var { name, .. } => buf.push(name.clone()),
|
Op::Var { name, .. } => collector_fun(name.clone()),
|
||||||
Op::Leaf(_) => (),
|
Op::Leaf(_) => (),
|
||||||
Op::Subtree { tokens, .. } => collect_vars(buf, tokens),
|
Op::Subtree { tokens, .. } => collect_vars(collector_fun, tokens),
|
||||||
Op::Repeat { tokens, .. } => collect_vars(buf, tokens),
|
Op::Repeat { tokens, .. } => collect_vars(collector_fun, tokens),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MetaTemplate {
|
impl MetaTemplate {
|
||||||
fn iter_delimited<'a>(&'a self, delimited: Option<&'a tt::Delimiter>) -> OpDelimitedIter<'a> {
|
fn iter_delimited<'a>(&'a self, delimited: Option<&'a tt::Delimiter>) -> OpDelimitedIter<'a> {
|
||||||
OpDelimitedIter { inner: &self.0, idx: 0, delimited }
|
OpDelimitedIter { inner: &self.0, idx: 0, delimited }
|
||||||
|
Loading…
Reference in New Issue
Block a user