From fab389002543f9a7c46522956dd8ce6bfe1752a4 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Sat, 24 Jul 2021 03:36:44 +0300 Subject: Refactor: Opt-out `if` stataments to select 1st param ... for some calls to `cmExpandedCommandArgument`. Signed-off-by: Alex Turbov --- Source/cmConditionEvaluator.cxx | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx index 530f8bc..4a9f95f 100644 --- a/Source/cmConditionEvaluator.cxx +++ b/Source/cmConditionEvaluator.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmConditionEvaluator.h" +#include #include #include #include @@ -55,6 +56,9 @@ std::string const keyVERSION_GREATER = "VERSION_GREATER"; std::string const keyVERSION_GREATER_EQUAL = "VERSION_GREATER_EQUAL"; std::string const keyVERSION_LESS = "VERSION_LESS"; std::string const keyVERSION_LESS_EQUAL = "VERSION_LESS_EQUAL"; + +std::array const ZERO_ONE_XLAT = { "0", "1" }; + } // anonymous namespace cmConditionEvaluator::cmConditionEvaluator(cmMakefile& makefile, @@ -312,10 +316,10 @@ void cmConditionEvaluator::IncrementArguments( cmArgumentList::iterator& argP2) const { if (argP1 != newArgs.end()) { - argP1++; + ++argP1; argP2 = argP1; if (argP1 != newArgs.end()) { - argP2++; + ++argP2; } } } @@ -327,11 +331,7 @@ void cmConditionEvaluator::HandlePredicate( cmArgumentList& newArgs, cmArgumentList::iterator& argP1, cmArgumentList::iterator& argP2) const { - if (value) { - *arg = cmExpandedCommandArgument("1", true); - } else { - *arg = cmExpandedCommandArgument("0", true); - } + *arg = cmExpandedCommandArgument(ZERO_ONE_XLAT[value], true); newArgs.erase(argP1); argP1 = arg; this->IncrementArguments(newArgs, argP1, argP2); @@ -346,11 +346,7 @@ void cmConditionEvaluator::HandleBinaryOp(const bool value, int& reducible, cmArgumentList::iterator& argP1, cmArgumentList::iterator& argP2) { - if (value) { - *arg = cmExpandedCommandArgument("1", true); - } else { - *arg = cmExpandedCommandArgument("0", true); - } + *arg = cmExpandedCommandArgument(ZERO_ONE_XLAT[value], true); newArgs.erase(argP2); newArgs.erase(argP1); argP1 = arg; @@ -399,12 +395,8 @@ bool cmConditionEvaluator::HandleLevel0(cmArgumentList& newArgs, newArgs2.pop_back(); // now recursively invoke IsTrue to handle the values inside the // parenthetical expression - bool value = this->IsTrue(newArgs2, errorString, status); - if (value) { - *arg = cmExpandedCommandArgument("1", true); - } else { - *arg = cmExpandedCommandArgument("0", true); - } + const bool value = this->IsTrue(newArgs2, errorString, status); + *arg = cmExpandedCommandArgument(ZERO_ONE_XLAT[value], true); argP1 = arg; argP1++; // remove the now evaluated parenthetical expression -- cgit v0.12