diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2023-10-10 15:17:36 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2023-11-01 12:52:09 +0100 |
commit | daa404713e8e1e5294a3cf65040172d33e43a0eb (patch) | |
tree | 9675014cc1e40fad7963e04d3ad3040293affc40 | |
parent | babea28312387a22642cb974cc4b97e9fe7fed49 (diff) | |
download | askama-daa404713e8e1e5294a3cf65040172d33e43a0eb.tar.gz askama-daa404713e8e1e5294a3cf65040172d33e43a0eb.tar.bz2 askama-daa404713e8e1e5294a3cf65040172d33e43a0eb.zip |
Avoid passing around duplicate data
-rw-r--r-- | askama_derive/src/generator.rs | 15 | ||||
-rw-r--r-- | 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<Writable<'a>>, // 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<String, CompileEr eprintln!("{:?}", templates[input.path.as_path()].nodes()); } - let code = Generator::new( - &input, - &contexts, - heritage.as_ref(), - MapChain::default(), - config.whitespace, - ) - .build(&contexts[input.path.as_path()])?; + let code = Generator::new(&input, &contexts, heritage.as_ref(), MapChain::default()) + .build(&contexts[input.path.as_path()])?; if input.print == Print::Code || input.print == Print::All { eprintln!("{code}"); } |