diff options
author | Douman <douman@gmx.se> | 2019-03-17 11:07:46 +0300 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2019-03-17 09:15:31 +0100 |
commit | 0b932a7b5e5dd1711cbeacd11ffa67be7d2d71f1 (patch) | |
tree | 88c67ae18ab0a0b7417bf003c86521233c2e15b6 | |
parent | 72b317b71428a1c0f63f920ebf2eecd26944f651 (diff) | |
download | askama-0b932a7b5e5dd1711cbeacd11ffa67be7d2d71f1.tar.gz askama-0b932a7b5e5dd1711cbeacd11ffa67be7d2d71f1.tar.bz2 askama-0b932a7b5e5dd1711cbeacd11ffa67be7d2d71f1.zip |
Use Template::size_hint to pre-allocate buffer
-rw-r--r-- | askama/src/lib.rs | 7 |
1 files 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<T: super::Template> TemplateIntoResponse for T { fn into_response(&self) -> Result<HttpResponse, Error> { - 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"))?; |