perf: reserve Vec capacities where appropriate

(cherry picked from commit 1e7d77c517)
This commit is contained in:
Will Lillis 2025-07-07 21:56:42 -04:00
parent bf4217f0ff
commit d7529c3265
12 changed files with 32 additions and 25 deletions

View file

@ -215,8 +215,9 @@ pub fn fuzz_language_corpus(
}
// Perform a random series of edits and reparse.
let mut undo_stack = Vec::new();
for _ in 0..=rand.unsigned(*EDIT_COUNT) {
let edit_count = rand.unsigned(*EDIT_COUNT);
let mut undo_stack = Vec::with_capacity(edit_count);
for _ in 0..=edit_count {
let edit = get_random_edit(&mut rand, &input);
undo_stack.push(invert_edit(&input, &edit));
perform_edit(&mut tree, &mut input, &edit).unwrap();