Skip to content

Commit

Permalink
Improve performance of find_used_templates
Browse files Browse the repository at this point in the history
Signed-off-by: max <[email protected]>
  • Loading branch information
PizzasBear committed Dec 7, 2023
1 parent ffb19b2 commit 2b57c80
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
21 changes: 15 additions & 6 deletions askama_derive/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,30 @@ impl TemplateInput<'_> {
.into());
}
dependency_graph.push(dependency_path);
let source = get_template_source(&extends)?;
check.push((extends, source));
if !map.contains_key(&extends) {
map.insert(extends.clone(), Parsed::default());
let source = get_template_source(&extends)?;
check.push((extends, source));
}
}
Node::Macro(m) if top => {
nested.push(&m.nodes);
}
Node::Import(import) if top => {
let import = self.config.find_template(import.path, Some(&path))?;
let source = get_template_source(&import)?;
check.push((import, source));
if !map.contains_key(&import) {
map.insert(import.clone(), Parsed::default());
let source = get_template_source(&import)?;
check.push((import, source));
}
}
Node::Include(include) => {
let include = self.config.find_template(include.path, Some(&path))?;
let source = get_template_source(&include)?;
check.push((include, source));
if !map.contains_key(&include) {
map.insert(include.clone(), Parsed::default());
let source = get_template_source(&include)?;
check.push((include, source));
}
}
Node::BlockDef(b) => {
nested.push(&b.nodes);
Expand Down
3 changes: 2 additions & 1 deletion askama_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ mod _parsed {
use super::node::Node;
use super::{Ast, ParseError, Syntax};

#[derive(Default)]
pub struct Parsed {
// `source` must outlive `ast`, so `ast` must be declared before `source`
ast: Ast<'static>,
Expand Down Expand Up @@ -68,7 +69,7 @@ mod _parsed {

pub use _parsed::Parsed;

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Ast<'a> {
nodes: Vec<Node<'a>>,
}
Expand Down

0 comments on commit 2b57c80

Please sign in to comment.