From bcf94d06cfd4c48da6ca9a4774c4891bdd946be3 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 15 Aug 2024 12:47:30 +0200 Subject: [PATCH] programmemory.cpp: avoid repeated iteration over values in `Executor::executeImpl()` --- lib/programmemory.cpp | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/programmemory.cpp b/lib/programmemory.cpp index af86ef98318..8e9f678d7d1 100644 --- a/lib/programmemory.cpp +++ b/lib/programmemory.cpp @@ -1411,18 +1411,34 @@ namespace { ValueFlow::Value executeImpl(const Token* expr) { - const ValueFlow::Value* value = nullptr; if (!expr) return unknown(); - if (expr->hasKnownIntValue() && !expr->isAssignmentOp() && expr->str() != ",") - return expr->values().front(); - if ((value = expr->getKnownValue(ValueFlow::Value::ValueType::FLOAT)) || - (value = expr->getKnownValue(ValueFlow::Value::ValueType::TOK)) || - (value = expr->getKnownValue(ValueFlow::Value::ValueType::ITERATOR_START)) || - (value = expr->getKnownValue(ValueFlow::Value::ValueType::ITERATOR_END)) || - (value = expr->getKnownValue(ValueFlow::Value::ValueType::CONTAINER_SIZE))) { - return *value; + const ValueFlow::Value* value = nullptr; + for (const auto& val : expr->values()) + { + if (!val.isKnown()) + continue; + switch (val.valueType) { + case ValueFlow::Value::ValueType::INT: { + if (!expr->isAssignmentOp() && expr->str() != ",") + return expr->values().front(); + break; + } + case ValueFlow::Value::ValueType::FLOAT: + case ValueFlow::Value::ValueType::TOK: + case ValueFlow::Value::ValueType::ITERATOR_START: + case ValueFlow::Value::ValueType::ITERATOR_END: + case ValueFlow::Value::ValueType::CONTAINER_SIZE: { + if (!value) + value = &val; + break; + } + default: + break; + } } + if (value) + return *value; if (expr->isNumber()) { if (MathLib::isFloat(expr->str())) return unknown();