From 51d9194a96df4cb8cd144afce4edc6e2122fab2d Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Tue, 27 Jul 2021 18:36:18 +0300 Subject: Refactor: Reduce one more condition checking on handling math compare --- Source/cmConditionEvaluator.cxx | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/Source/cmConditionEvaluator.cxx b/Source/cmConditionEvaluator.cxx index 570bb4a..8224121 100644 --- a/Source/cmConditionEvaluator.cxx +++ b/Source/cmConditionEvaluator.cxx @@ -619,18 +619,18 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs, double lhs; double rhs; - bool result; - if (std::sscanf(ldef->c_str(), "%lg", &lhs) != 1 || - std::sscanf(rdef->c_str(), "%lg", &rhs) != 1) { - result = false; - } else { + auto parseDoubles = [&]() { + return std::sscanf(ldef->c_str(), "%lg", &lhs) == 1 && + std::sscanf(rdef->c_str(), "%lg", &rhs) == 1; + }; + const auto result = parseDoubles() && // clang-format off - result = cmRt2CtSelector< - std::less, std::less_equal, std::greater, - std::greater_equal, std::equal_to + cmRt2CtSelector< + std::less, std::less_equal, + std::greater, std::greater_equal, + std::equal_to >::eval(matchNo, lhs, rhs); - // clang-format on - } + // clang-format on HandleBinaryOp(result, newArgs, arg, argP1, argP2); } @@ -643,8 +643,9 @@ bool cmConditionEvaluator::HandleLevel2(cmArgumentList& newArgs, const auto val = (*lhs).compare(*rhs); // clang-format off const auto result = cmRt2CtSelector< - std::less, std::less_equal, std::greater, - std::greater_equal, std::equal_to + std::less, std::less_equal, + std::greater, std::greater_equal, + std::equal_to >::eval(matchNo, val, 0); // clang-format on HandleBinaryOp(result, newArgs, arg, argP1, argP2); -- cgit v0.12