Skip to content

Commit

Permalink
Skip caching calls (Resolves #667)
Browse files Browse the repository at this point in the history
  • Loading branch information
vallentin committed Apr 19, 2022
1 parent fc779e2 commit 393060f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions askama_shared/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,11 +1058,12 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
expr_buf.buf, self.input.escaper
),
};
let is_cacheable = !matches!(s, Expr::Call(..));

use std::collections::hash_map::Entry;
let id = match expr_cache.entry(expression.clone()) {
Entry::Occupied(e) => *e.get(),
Entry::Vacant(e) => {
Entry::Occupied(e) if is_cacheable => *e.get(),
e => {
let id = self.named;
self.named += 1;

Expand All @@ -1071,7 +1072,10 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> {
buf_expr.write(&expression);
buf_expr.writeln(",")?;

e.insert(id);
if let Entry::Vacant(e) = e {
e.insert(id);
}

id
}
};
Expand Down

0 comments on commit 393060f

Please sign in to comment.