Pre-allocate sufficient size for our output String
This commit is contained in:
parent
2d6558c769
commit
f75da83a60
1 changed files with 4 additions and 6 deletions
|
@ -10,7 +10,7 @@ extern crate proc_macro;
|
||||||
mod parse;
|
mod parse;
|
||||||
mod build;
|
mod build;
|
||||||
|
|
||||||
use proc_macro::{Span, Term, TokenStream, TokenTree};
|
use proc_macro::{Literal, Span, Term, TokenStream, TokenTree};
|
||||||
use proc_macro::quote;
|
use proc_macro::quote;
|
||||||
|
|
||||||
type ParseResult<T> = Result<T, String>;
|
type ParseResult<T> = Result<T, String>;
|
||||||
|
@ -32,17 +32,15 @@ fn expand(input: TokenStream) -> TokenStream {
|
||||||
let output_ident = TokenTree::Term(Term::new("__maud_output", Span::def_site()));
|
let output_ident = TokenTree::Term(Term::new("__maud_output", Span::def_site()));
|
||||||
// Heuristic: the size of the resulting markup tends to correlate with the
|
// Heuristic: the size of the resulting markup tends to correlate with the
|
||||||
// code size of the template itself
|
// code size of the template itself
|
||||||
//
|
let size_hint = input.to_string().len();
|
||||||
// NOTE: can't get this to compile inside quote!
|
let size_hint = TokenTree::Literal(Literal::u64_unsuffixed(size_hint as u64));
|
||||||
//let size_hint = Literal::u64_unsuffixed(size_hint as u64);
|
|
||||||
let stmts = match parse::parse(input, output_ident.clone()) {
|
let stmts = match parse::parse(input, output_ident.clone()) {
|
||||||
Ok(stmts) => stmts,
|
Ok(stmts) => stmts,
|
||||||
Err(e) => panic!(e),
|
Err(e) => panic!(e),
|
||||||
};
|
};
|
||||||
quote!({
|
quote!({
|
||||||
extern crate maud;
|
extern crate maud;
|
||||||
//let mut $output_ident = String::with_capacity($size_hint as usize);
|
let mut $output_ident = String::with_capacity($size_hint as usize);
|
||||||
let mut $output_ident = String::new();
|
|
||||||
$stmts
|
$stmts
|
||||||
maud::PreEscaped($output_ident)
|
maud::PreEscaped($output_ident)
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Reference in a new issue