Skip to content

Commit e1099bb

Browse files
committed
Save a little clone, again
1 parent 10bbb00 commit e1099bb

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/render.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,12 @@ impl<'a> Renderer<'a> {
431431
// We need to make a new context for the macro from the arguments given
432432
// Return an error if we get some unknown params
433433
let mut context = HashMap::new();
434-
for (param_name, exp) in call_params.clone() {
434+
for (param_name, exp) in &call_params {
435435
if !params.contains(&param_name) {
436436
let params_seen = call_params.keys().cloned().collect::<Vec<String>>();
437437
bail!("Macro `{}` got `{:?}` for args but was expecting `{:?}` (order does not matter)", macro_name, params, params_seen);
438438
}
439-
context.insert(param_name.to_string(), self.eval_expression(exp)?);
439+
context.insert(param_name.to_string(), self.eval_expression(exp.clone())?);
440440
}
441441

442442
// Push this context to our stack of macro context so the renderer can pick variables
@@ -555,10 +555,10 @@ impl<'a> Renderer<'a> {
555555

556556
match self.template.blocks_definitions.get(&name) {
557557
Some(b) => {
558-
match b[new_level].clone() {
559-
(tpl_name, Block { body, .. }) => {
560-
self.blocks.push((name.clone(), new_level));
561-
let has_macro = self.import_macros(tpl_name)?;
558+
match &b[new_level] {
559+
&(ref tpl_name, Block { ref body, .. }) => {
560+
self.blocks.push((name, new_level));
561+
let has_macro = self.import_macros(tpl_name.clone())?;
562562
let res = self.render_node(*body.clone());
563563
if has_macro {
564564
self.macros.pop();

src/template.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ impl Template {
4141
let mut blocks = HashMap::new();
4242
// We find all those blocks at first so we don't need to do it for each render
4343
// Recursive because we can have blocks inside blocks
44-
fn find_blocks(tpl_name: String, ast: LinkedList<Node>, blocks: &mut HashMap<String, Node>) -> Result<()> {
44+
fn find_blocks(tpl_name: &str, ast: LinkedList<Node>, blocks: &mut HashMap<String, Node>) -> Result<()> {
4545
for node in ast {
4646
match node {
4747
Node::Block { ref name, ref body } => {
4848
if blocks.contains_key(name) {
4949
bail!("Block `{}` is duplicated", name);
5050
}
5151
blocks.insert(name.to_string(), node.clone());
52-
find_blocks(tpl_name.clone(), body.get_children(), blocks)?;
52+
find_blocks(tpl_name, body.get_children(), blocks)?;
5353
},
5454
_ => continue,
5555
};
5656
}
5757

5858
Ok(())
5959
}
60-
find_blocks(tpl_name.to_string(), ast.get_children(), &mut blocks)?;
60+
find_blocks(tpl_name, ast.get_children(), &mut blocks)?;
6161

6262
// We also find all macros defined/imported in the template file
6363
let mut macros = HashMap::new();

0 commit comments

Comments
 (0)