From 90433f6ea3b2676f97991d89f14a9028bab6577b Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Tue, 8 Sep 2020 11:54:22 -0500 Subject: [PATCH] Minimize AST node vector reallocations Closes #7201 --- src/ast.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ast.cpp b/src/ast.cpp index 39fe5d2ff..c8749df0f 100644 --- a/src/ast.cpp +++ b/src/ast.cpp @@ -915,7 +915,11 @@ class ast_t::populator_t { // Now try parsing a node. if (auto node = this->try_parse()) { - 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();