We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 948ce3f commit f1b6891Copy full SHA for f1b6891
crates/djls-templates/src/lexer.rs
@@ -20,7 +20,11 @@ impl Lexer {
20
}
21
22
pub fn tokenize(&mut self) -> Vec<Token> {
23
- let mut tokens = Vec::new();
+ // Conservative estimate: most templates have 1 token per 15-20 chars
24
+ // Min 32 to avoid reallocation for tiny templates
25
+ // Max 1024 to avoid over-allocation for huge templates
26
+ let estimated_tokens = (self.source.len() / 15).clamp(32, 1024);
27
+ let mut tokens = Vec::with_capacity(estimated_tokens);
28
29
while !self.is_at_end() {
30
self.start = self.current;
0 commit comments