diff --git a/lib/astutils.h b/lib/astutils.h index 6bdde92b1..0dafe305d 100644 --- a/lib/astutils.h +++ b/lib/astutils.h @@ -53,7 +53,11 @@ void visitAstNodes(T *ast, const TFunc &visitor) if (!ast) return; - std::stack> tokens; + std::vector tokensContainer; + // the size of 8 was determined in tests to be sufficient to avoid excess allocations. also add 1 as a buffer. + // we might need to increase that value in the future. + tokensContainer.reserve(8 + 1); + std::stack> tokens(std::move(tokensContainer)); T *tok = ast; do { ChildrenToVisit c = visitor(tok);