Reuse previous Vec allocation in loop (#15428)

Minor optimization to avoid deallocating/reallocating a new `Vec` in the
top `check_doc` loop.

changelog: none

r? blyxyas
This commit is contained in:
Alejandra González 2025-08-07 18:21:20 +00:00 committed by GitHub
commit 32a216ecab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1139,12 +1139,12 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
None,
"a backtick may be missing a pair",
);
text_to_check.clear();
} else {
for (text, range, assoc_code_level) in text_to_check {
for (text, range, assoc_code_level) in text_to_check.drain(..) {
markdown::check(cx, valid_idents, &text, &fragments, range, assoc_code_level, blockquote_level);
}
}
text_to_check = Vec::new();
},
Start(FootnoteDefinition(..)) => in_footnote_definition = true,
End(TagEnd::FootnoteDefinition) => in_footnote_definition = false,