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 Jan 17, 2024
1 parent 143122a commit 8929053
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions askama_derive/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,13 @@ impl TemplateInput<'_> {
while let Some(nodes) = nested.pop() {
for n in nodes {
let mut add_to_check = |path: PathBuf| -> Result<(), CompileError> {
let source = get_template_source(&path)?;
check.push((path, source));
if !map.contains_key(&path) {
// Add a dummy entry to `map` in order to prevent adding `path`
// multiple times to `check`.
map.insert(path.clone(), Parsed::default());
let source = get_template_source(&path)?;
check.push((path, source));
}
Ok(())
};

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 8929053

Please sign in to comment.