mirror of
https://github.com/askama-rs/askama.git
synced 2025-10-02 15:25:19 +00:00
Improve performance of find_used_templates
Signed-off-by: max <gmx.sht@gmail.com>
This commit is contained in:
parent
411efb8927
commit
2c7759c0d0
@ -119,8 +119,13 @@ impl TemplateInput<'_> {
|
|||||||
while let Some(nodes) = nested.pop() {
|
while let Some(nodes) = nested.pop() {
|
||||||
for n in nodes {
|
for n in nodes {
|
||||||
let mut add_to_check = |path: PathBuf| -> Result<(), CompileError> {
|
let mut add_to_check = |path: PathBuf| -> Result<(), CompileError> {
|
||||||
let source = get_template_source(&path)?;
|
if !map.contains_key(&path) {
|
||||||
check.push((path, source));
|
// 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(())
|
Ok(())
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ mod _parsed {
|
|||||||
use super::node::Node;
|
use super::node::Node;
|
||||||
use super::{Ast, ParseError, Syntax};
|
use super::{Ast, ParseError, Syntax};
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct Parsed {
|
pub struct Parsed {
|
||||||
// `source` must outlive `ast`, so `ast` must be declared before `source`
|
// `source` must outlive `ast`, so `ast` must be declared before `source`
|
||||||
ast: Ast<'static>,
|
ast: Ast<'static>,
|
||||||
@ -68,7 +69,7 @@ mod _parsed {
|
|||||||
|
|
||||||
pub use _parsed::Parsed;
|
pub use _parsed::Parsed;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Ast<'a> {
|
pub struct Ast<'a> {
|
||||||
nodes: Vec<Node<'a>>,
|
nodes: Vec<Node<'a>>,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user