Skip to content

Commit

Permalink
Save a little clone, again
Browse files Browse the repository at this point in the history
  • Loading branch information
wdv4758h committed Dec 30, 2016
1 parent 10bbb00 commit e1099bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,12 +431,12 @@ impl<'a> Renderer<'a> {
// We need to make a new context for the macro from the arguments given
// Return an error if we get some unknown params
let mut context = HashMap::new();
for (param_name, exp) in call_params.clone() {
for (param_name, exp) in &call_params {
if !params.contains(&param_name) {
let params_seen = call_params.keys().cloned().collect::<Vec<String>>();
bail!("Macro `{}` got `{:?}` for args but was expecting `{:?}` (order does not matter)", macro_name, params, params_seen);
}
context.insert(param_name.to_string(), self.eval_expression(exp)?);
context.insert(param_name.to_string(), self.eval_expression(exp.clone())?);
}

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

match self.template.blocks_definitions.get(&name) {
Some(b) => {
match b[new_level].clone() {
(tpl_name, Block { body, .. }) => {
self.blocks.push((name.clone(), new_level));
let has_macro = self.import_macros(tpl_name)?;
match &b[new_level] {
&(ref tpl_name, Block { ref body, .. }) => {
self.blocks.push((name, new_level));
let has_macro = self.import_macros(tpl_name.clone())?;
let res = self.render_node(*body.clone());
if has_macro {
self.macros.pop();
Expand Down
6 changes: 3 additions & 3 deletions src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ impl Template {
let mut blocks = HashMap::new();
// We find all those blocks at first so we don't need to do it for each render
// Recursive because we can have blocks inside blocks
fn find_blocks(tpl_name: String, ast: LinkedList<Node>, blocks: &mut HashMap<String, Node>) -> Result<()> {
fn find_blocks(tpl_name: &str, ast: LinkedList<Node>, blocks: &mut HashMap<String, Node>) -> Result<()> {
for node in ast {
match node {
Node::Block { ref name, ref body } => {
if blocks.contains_key(name) {
bail!("Block `{}` is duplicated", name);
}
blocks.insert(name.to_string(), node.clone());
find_blocks(tpl_name.clone(), body.get_children(), blocks)?;
find_blocks(tpl_name, body.get_children(), blocks)?;
},
_ => continue,
};
}

Ok(())
}
find_blocks(tpl_name.to_string(), ast.get_children(), &mut blocks)?;
find_blocks(tpl_name, ast.get_children(), &mut blocks)?;

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

0 comments on commit e1099bb

Please sign in to comment.