Skip to content

Commit

Permalink
programmemory.cpp: avoid repeated iteration over values in `Executor:…
Browse files Browse the repository at this point in the history
…:executeImpl()`
  • Loading branch information
firewave committed Aug 15, 2024
1 parent 1aee490 commit bcf94d0
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions lib/programmemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit bcf94d0

Please sign in to comment.