From 0b932a7b5e5dd1711cbeacd11ffa67be7d2d71f1 Mon Sep 17 00:00:00 2001 From: Douman Date: Sun, 17 Mar 2019 11:07:46 +0300 Subject: Use Template::size_hint to pre-allocate buffer --- askama/src/lib.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/askama/src/lib.rs b/askama/src/lib.rs index 8492d8f..694f298 100644 --- a/askama/src/lib.rs +++ b/askama/src/lib.rs @@ -500,9 +500,9 @@ pub mod actix_web { impl BytesWriter { #[inline] - pub fn new() -> Self { + pub fn with_capacity(size: usize) -> Self { Self { - buf: bytes::BytesMut::with_capacity(4096) + buf: bytes::BytesMut::with_capacity(size) } } @@ -510,7 +510,6 @@ pub mod actix_web { pub fn freeze(self) -> bytes::Bytes { self.buf.freeze() } - } impl fmt::Write for BytesWriter { @@ -536,7 +535,7 @@ pub mod actix_web { impl TemplateIntoResponse for T { fn into_response(&self) -> Result { - let mut buffer = BytesWriter::new(); + let mut buffer = BytesWriter::with_capacity(T::size_hint()); self.render_into(&mut buffer) .map_err(|_| ErrorInternalServerError("Template parsing error"))?; -- cgit