Skip to content

Commit 47988bb

Browse files
improve parse_block perf slightly (#262)
1 parent 4c90a89 commit 47988bb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

crates/djls-templates/src/parser.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ impl Parser {
1717
}
1818

1919
pub fn parse(&mut self) -> (Vec<Node>, Vec<ParseError>) {
20-
let mut nodelist = Vec::new();
21-
let mut errors = Vec::new();
20+
let mut nodelist = Vec::with_capacity(self.tokens.len() / 2);
21+
let mut errors = Vec::with_capacity(4);
2222

2323
while !self.is_at_end() {
2424
match self.next_node() {
@@ -85,11 +85,15 @@ impl Parser {
8585
});
8686
};
8787

88-
let mut parts = content_ref.split_whitespace();
88+
let mut parts = content_ref.split_ascii_whitespace();
8989

9090
let name = parts.next().ok_or(ParseError::EmptyTag)?.to_string();
9191

92-
let bits = parts.map(std::string::ToString::to_string).collect();
92+
let mut bits = Vec::with_capacity(parts.clone().count());
93+
for part in parts {
94+
bits.push(part.to_owned());
95+
}
96+
9397
let span = token.content_span_or_fallback();
9498

9599
Ok(Node::Tag { name, bits, span })

0 commit comments

Comments
 (0)