Skip to content

Commit

Permalink
parser: allocate vector with exact capacity (#894)
Browse files Browse the repository at this point in the history
This tweaks `parse_content()` logic in order to reduce the amount
of vector growing, as the final vector capacity is already known
beforehand.
  • Loading branch information
lucab authored Feb 12, 2024
1 parent 93c92b9 commit cafe175
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,9 +1044,10 @@ fn parse_if(pair: Pair<Rule>) -> TeraResult<Node> {
}

fn parse_content(pair: Pair<Rule>) -> TeraResult<Vec<Node>> {
let mut nodes = vec![];
let pairs = pair.into_inner();
let mut nodes = Vec::with_capacity(pairs.len());

for p in pair.into_inner() {
for p in pairs {
match p.as_rule() {
Rule::include_tag => nodes.push(parse_include(p)),
Rule::comment_tag => nodes.push(parse_comment_tag(p)),
Expand Down

0 comments on commit cafe175

Please sign in to comment.