diff options
author | bott <mhpoin@gmail.com> | 2018-10-26 03:36:54 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2018-10-26 03:55:53 +0200 |
commit | 76d29eb5912b91f9222c8e542673902fb87d2ae0 (patch) | |
tree | d5c28f2ec46d2068f371011439f30f13ec3964d9 /askama_derive/src/generator.rs | |
parent | 7062aabbcbb98bdeacda94071111f0fcc13a918d (diff) | |
download | askama-76d29eb5912b91f9222c8e542673902fb87d2ae0.tar.gz askama-76d29eb5912b91f9222c8e542673902fb87d2ae0.tar.bz2 askama-76d29eb5912b91f9222c8e542673902fb87d2ae0.zip |
Improve bench reducing the number of calls to writer.write_str
Diffstat (limited to 'askama_derive/src/generator.rs')
-rw-r--r-- | askama_derive/src/generator.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index bc009f9..49c0d02 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -597,18 +597,27 @@ impl<'a> Generator<'a> { fn write_lit(&mut self, buf: &mut Buffer, lws: &'a str, val: &str, rws: &'a str) { assert!(self.next_ws.is_none()); - if !lws.is_empty() { + let lws_write = if !lws.is_empty() { if self.skip_ws { self.skip_ws = false; + false } else if val.is_empty() { assert!(rws.is_empty()); self.next_ws = Some(lws); + false } else { - buf.writeln(&format!("writer.write_str({:#?})?;", lws)); + true } - } + } else { + false + }; + if !val.is_empty() { - buf.writeln(&format!("writer.write_str({:#?})?;", val)); + if lws_write { + buf.writeln(&format!("writer.write_str({:#?})?;", [lws, val].join(""))); + } else { + buf.writeln(&format!("writer.write_str({:#?})?;", val)); + } } if !rws.is_empty() { self.next_ws = Some(rws); |