From 58eec66b49a2a7156b745753c50080b8afad6b7a Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 20 Nov 2018 09:11:09 -0700 Subject: [PATCH] perf: Default buffer size Can always use `render_to` if this is too large. --- src/template.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/template.rs b/src/template.rs index 0af2c89b7..17f2083d4 100644 --- a/src/template.rs +++ b/src/template.rs @@ -14,7 +14,8 @@ pub struct Template { impl Template { /// Renders an instance of the Template, using the given globals. pub fn render(&self, globals: &interpreter::Globals) -> Result { - let mut data = Vec::new(); + const BEST_GUESS: usize = 10_000; + let mut data = Vec::with_capacity(BEST_GUESS); self.render_to(&mut data, globals)?; Ok(String::from_utf8(data).expect("render only writes UTF-8")) }