Skip to content

Commit bd10ed4

Browse files
committed
valueflow.cpp: exit early in LifetimeStore::byVal() to avoid unnecessary object creation
1 parent ae7b70f commit bd10ed4

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

lib/valueflow.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,19 +2362,20 @@ struct LifetimeStore {
23622362
for (const ValueFlow::LifetimeToken& lt : ValueFlow::getLifetimeTokens(argtok, settings)) {
23632363
if (!settings.certainty.isEnabled(Certainty::inconclusive) && lt.inconclusive)
23642364
continue;
2365+
2366+
const Variable* var = lt.token->variable();
2367+
if (!var || !var->isArgument())
2368+
continue;
2369+
23652370
ValueFlow::Value value;
23662371
value.valueType = ValueFlow::Value::ValueType::LIFETIME;
23672372
value.tokvalue = lt.token;
23682373
value.capturetok = argtok;
23692374
value.errorPath = er;
23702375
value.lifetimeKind = type;
23712376
value.setInconclusive(inconclusive || lt.inconclusive);
2372-
const Variable* var = lt.token->variable();
2373-
if (var && var->isArgument()) {
2374-
value.lifetimeScope = ValueFlow::Value::LifetimeScope::Argument;
2375-
} else {
2376-
continue;
2377-
}
2377+
value.lifetimeScope = ValueFlow::Value::LifetimeScope::Argument;
2378+
23782379
// Don't add the value a second time
23792380
if (std::find(tok->values().cbegin(), tok->values().cend(), value) != tok->values().cend())
23802381
continue;

0 commit comments

Comments
 (0)