From 95fc27cedde069c884d151644bf1e7ef105dc7da Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sun, 25 Jul 2021 03:41:26 +0300 Subject: Refactor: Rewrite parenthesis scanner to avoid `if`s Signed-off-by: Alex Turbov --- Source/cmConditionEvaluator.cxx | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx index be7ae88..ef05560 100644 --- a/Source/cmConditionEvaluator.cxx +++ b/Source/cmConditionEvaluator.cxx @@ -362,18 +362,11 @@ bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs, for (auto arg = newArgs.begin(); arg != newArgs.end(); ++arg) { if (this->IsKeyword(keyParenL, *arg)) { // search for the closing paren for this opening one - cmArgumentList::iterator argClose; - argClose = arg; - argClose++; - auto depth = 1u; - while (argClose != newArgs.end() && depth) { - if (this->IsKeyword(keyParenL, *argClose)) { - depth++; - } - if (this->IsKeyword(keyParenR, *argClose)) { - depth--; - } - argClose++; + auto depth = 1; + auto argClose = std::next(arg); + for (; argClose != newArgs.end() && depth; ++argClose) { + depth += int(this->IsKeyword(keyParenL, *argClose)) - + int(this->IsKeyword(keyParenR, *argClose)); } if (depth) { errorString = "mismatched parenthesis in condition"; -- cgit v0.12