From daa404713e8e1e5294a3cf65040172d33e43a0eb Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Tue, 10 Oct 2023 15:17:36 +0200 Subject: Avoid passing around duplicate data --- askama_derive/src/generator.rs | 15 ++------------- askama_derive/src/lib.rs | 10 ++-------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 929e18c..9031e8b 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -37,9 +37,6 @@ pub(crate) struct Generator<'a> { buf_writable: Vec>, // Counter for write! hash named arguments named: usize, - // If set to `suppress`, the whitespace characters will be removed by default unless `+` is - // used. - whitespace: WhitespaceHandling, } impl<'a> Generator<'a> { @@ -48,7 +45,6 @@ impl<'a> Generator<'a> { contexts: &'n HashMap<&'n Path, Context<'n>>, heritage: Option<&'n Heritage<'_>>, locals: MapChain<'n, &'n str, LocalMeta>, - whitespace: WhitespaceHandling, ) -> Generator<'n> { Generator { input, @@ -61,7 +57,6 @@ impl<'a> Generator<'a> { super_block: None, buf_writable: vec![], named: 0, - whitespace, } } @@ -796,13 +791,7 @@ impl<'a> Generator<'a> { // handle the include's nodes. Unfortunately we can't easily share the `includes` cache. let locals = MapChain::with_parent(&self.locals); - let mut child = Self::new( - self.input, - self.contexts, - self.heritage, - locals, - self.whitespace, - ); + let mut child = Self::new(self.input, self.contexts, self.heritage, locals); let nodes = match self.contexts.get(path.as_path()) { Some(ctx) => ctx.nodes, @@ -1638,7 +1627,7 @@ impl<'a> Generator<'a> { Some(Whitespace::Suppress) => WhitespaceHandling::Suppress, Some(Whitespace::Preserve) => WhitespaceHandling::Preserve, Some(Whitespace::Minimize) => WhitespaceHandling::Minimize, - None => self.whitespace, + None => self.input.config.whitespace, } } diff --git a/askama_derive/src/lib.rs b/askama_derive/src/lib.rs index a5eb67a..547a449 100644 --- a/askama_derive/src/lib.rs +++ b/askama_derive/src/lib.rs @@ -60,14 +60,8 @@ pub(crate) fn build_template(ast: &syn::DeriveInput) -> Result