From dddc39b4a4af5d639e352763472e6b4877bf8240 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 3 Jun 2025 14:52:27 +0200 Subject: [PATCH] astutils.h: removed unnecessary `std::stack` usage from `visitAstNodes()` saves about 10% of Ir --- lib/astutils.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/astutils.h b/lib/astutils.h index a1781ea1edf..c7d25be0353 100644 --- a/lib/astutils.h +++ b/lib/astutils.h @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -64,29 +63,29 @@ void visitAstNodes(T *ast, const TFunc &visitor) // 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. - std::stack> tokens; + SmallVector tokens; T *tok = ast; do { const ChildrenToVisit c = visitor(tok); - if (c == ChildrenToVisit::done) break; + if (c == ChildrenToVisit::op2 || c == ChildrenToVisit::op1_and_op2) { T *t2 = tok->astOperand2(); if (t2) - tokens.push(t2); + tokens.push_back(t2); } if (c == ChildrenToVisit::op1 || c == ChildrenToVisit::op1_and_op2) { T *t1 = tok->astOperand1(); if (t1) - tokens.push(t1); + tokens.push_back(t1); } if (tokens.empty()) break; - tok = tokens.top(); - tokens.pop(); + tok = tokens.back(); + tokens.pop_back(); } while (true); }