aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-08-06 20:55:41 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2017-08-06 20:55:41 +0200
commited2fd2b1053fac08bc2e4fa4a6de2d79c136d636 (patch)
tree64cdd083e620048d94dcec75eb65f1ac53440384 /askama_derive
parent47df34c0f000429511fda7982e3ef1b4cd2d4569 (diff)
downloadaskama-ed2fd2b1053fac08bc2e4fa4a6de2d79c136d636.tar.gz
askama-ed2fd2b1053fac08bc2e4fa4a6de2d79c136d636.tar.bz2
askama-ed2fd2b1053fac08bc2e4fa4a6de2d79c136d636.zip
Share HashSet for locals among nested Generators
Diffstat (limited to 'askama_derive')
-rw-r--r--askama_derive/src/generator.rs24
1 files changed, 14 insertions, 10 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs
index e24aaa8..16d7c9e 100644
--- a/askama_derive/src/generator.rs
+++ b/askama_derive/src/generator.rs
@@ -22,14 +22,14 @@ struct Generator<'a> {
buf: String,
indent: u8,
start: bool,
- locals: HashSet<String>,
+ locals: &'a mut HashSet<String>,
next_ws: Option<&'a str>,
skip_ws: bool,
}
impl<'a> Generator<'a> {
- fn new(locals: HashSet<String>, indent: u8) -> Generator<'a> {
+ fn new<'n>(locals: &'n mut HashSet<String>, indent: u8) -> Generator<'n> {
Generator {
buf: String::new(),
indent: indent,
@@ -40,12 +40,12 @@ impl<'a> Generator<'a> {
}
}
- fn default() -> Generator<'a> {
- Self::new(HashSet::new(), 0)
+ fn default<'n>(locals: &'n mut HashSet<String>) -> Generator<'n> {
+ Self::new(locals, 0)
}
- fn child(&self) -> Generator<'a> {
- Self::new(self.locals.clone(), self.indent)
+ fn child<'n>(&'n mut self) -> Generator<'n> {
+ Self::new(self.locals, self.indent)
}
fn indent(&mut self) {
@@ -297,9 +297,12 @@ impl<'a> Generator<'a> {
let path = path::find_template_from_path(&path, None);
let src = path::get_template_source(&path);
let nodes = parser::parse(&src);
- let mut gen = self.child();
- gen.handle(&nodes);
- self.buf.push_str(&gen.result());
+ let nested = {
+ let mut gen = self.child();
+ gen.handle(&nodes);
+ gen.result()
+ };
+ self.buf.push_str(&nested);
self.flush_ws(ws);
}
@@ -470,7 +473,8 @@ pub fn generate(ast: &syn::DeriveInput, path: &str, mut nodes: Vec<Node>) -> Str
}
}
- let mut gen = Generator::default();
+ let mut locals = HashSet::new();
+ let mut gen = Generator::default(&mut locals);
if !blocks.is_empty() {
if base.is_none() {
gen.define_trait(path, &block_names);