From 2148b8b165694381edcb0c1bce19dfb0e3e5ca04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Mon, 17 Jan 2022 20:34:35 +0100 Subject: [PATCH] astutils.cpp: optimized visitAstNodesGeneric() a bit (#3716) --- lib/astutils.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index cef5b5627..8e260fb24 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -42,7 +42,7 @@ template )> void visitAstNodesGeneric(T *ast, std::function visitor) { - std::stack tokens; + std::stack> tokens; tokens.push(ast); while (!tokens.empty()) { T *tok = tokens.top(); @@ -54,10 +54,16 @@ void visitAstNodesGeneric(T *ast, std::function visitor) if (c == ChildrenToVisit::done) break; - if (c == ChildrenToVisit::op2 || c == ChildrenToVisit::op1_and_op2) - tokens.push(tok->astOperand2()); - if (c == ChildrenToVisit::op1 || c == ChildrenToVisit::op1_and_op2) - tokens.push(tok->astOperand1()); + if (c == ChildrenToVisit::op2 || c == ChildrenToVisit::op1_and_op2) { + T *t2 = tok->astOperand2(); + if (t2) + tokens.push(t2); + } + if (c == ChildrenToVisit::op1 || c == ChildrenToVisit::op1_and_op2) { + T *t1 = tok->astOperand1(); + if (t1) + tokens.push(t1); + } } }