perf: join after loop-optimization

This commit is contained in:
Kogia-sima 2020-12-24 17:22:11 +09:00
parent 1128fda3d3
commit 348a3825f2
2 changed files with 11 additions and 4 deletions

View File

@ -88,6 +88,15 @@ impl VisitMut for OptmizerImpl {
let mut concat = sl;
concat += sf.as_str();
let mut previous;
if let Some(prev) = results.last().and_then(get_rendertext_value_from_stmt) {
results.pop();
previous = prev;
previous += sf.as_str();
} else {
previous = sf;
}
fl.body.stmts.remove(0);
*fl.body.stmts.last_mut().unwrap() = syn::parse2(quote! {
__sf_rt::render_text!(__sf_buf, #concat);
@ -95,7 +104,7 @@ impl VisitMut for OptmizerImpl {
.unwrap();
let mut new_stmts = syn::parse2::<Block>(quote! {{
__sf_rt::render_text!(__sf_buf, #sf);
__sf_rt::render_text!(__sf_buf, #previous);
#stmt
unsafe { __sf_buf._set_len(__sf_buf.len() - #sf_len); }
}})

View File

@ -245,9 +245,7 @@ fn derive_template_impl(tokens: TokenStream) -> Result<TokenStream, syn::Error>
use sailfish::runtime::{Buffer, SizeHint};
static SIZE_HINT: SizeHint = SizeHint::new();
let mut buf = Buffer::new();
buf.reserve(SIZE_HINT.get());
let mut buf = Buffer::with_capacity(SIZE_HINT.get());
self.render_once_to(&mut buf)?;
SIZE_HINT.update(buf.len());