Minimize AST node vector reallocations

Closes #7201
This commit is contained in:
Mahmoud Al-Qudsi
2020-09-08 11:54:22 -05:00
parent 0f674435a3
commit 90433f6ea3

View File

@@ -915,7 +915,11 @@ class ast_t::populator_t {
// Now try parsing a node.
if (auto node = this->try_parse<ContentsNode>()) {
contents.push_back(std::move(node));
// #7201: Minimize reallocations of contents vector
if (contents.empty()) {
contents.reserve(64);
}
contents.emplace_back(std::move(node));
} else if (exhaust_stream && peek_type() != parse_token_type_t::terminate) {
// We aren't allowed to stop. Produce an error and keep going.
consume_excess_token_generating_error();