Skip to content

Commit 07ef476

Browse files
committed
valueflow.cpp: refactored valueFlowForwardLifetime() to avoid unnecessary operations
1 parent cb2c374 commit 07ef476

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

lib/valueflow.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,11 +1934,9 @@ static void valueFlowForwardLifetime(Token * tok, const TokenList &tokenlist, Er
19341934
if (!expr)
19351935
return;
19361936

1937-
if (expr->exprId() == 0)
1937+
if (expr->exprId() <= 0)
19381938
return;
19391939

1940-
const Token* endOfVarScope = ValueFlow::getEndOfExprScope(expr);
1941-
19421940
// Only forward lifetime values
19431941
std::list<ValueFlow::Value> values = parent->astOperand2()->values();
19441942
values.remove_if(&isNotLifetimeValue);
@@ -1951,21 +1949,21 @@ static void valueFlowForwardLifetime(Token * tok, const TokenList &tokenlist, Er
19511949

19521950
// Skip RHS
19531951
Token* nextExpression = nextAfterAstRightmostLeaf(parent);
1952+
const Token* endOfVarScope = ValueFlow::getEndOfExprScope(expr);
19541953

1955-
if (expr->exprId() > 0) {
1956-
valueFlowForward(nextExpression, endOfVarScope->next(), expr, values, tokenlist, errorLogger, settings);
1954+
valueFlowForward(nextExpression, endOfVarScope->next(), expr, values, tokenlist, errorLogger, settings);
19571955

1956+
// TODO: handle `[`
1957+
if (Token::simpleMatch(parent->astOperand1(), ".")) {
19581958
for (ValueFlow::Value& val : values) {
19591959
if (val.lifetimeKind == ValueFlow::Value::LifetimeKind::Address)
19601960
val.lifetimeKind = ValueFlow::Value::LifetimeKind::SubObject;
19611961
}
1962-
// TODO: handle `[`
1963-
if (Token::simpleMatch(parent->astOperand1(), ".")) {
1964-
const Token* parentLifetime =
1965-
getParentLifetime(parent->astOperand1()->astOperand2(), settings.library);
1966-
if (parentLifetime && parentLifetime->exprId() > 0) {
1967-
valueFlowForward(nextExpression, endOfVarScope, parentLifetime, std::move(values), tokenlist, errorLogger, settings);
1968-
}
1962+
1963+
const Token* parentLifetime =
1964+
getParentLifetime(parent->astOperand1()->astOperand2(), settings.library);
1965+
if (parentLifetime && parentLifetime->exprId() > 0) {
1966+
valueFlowForward(nextExpression, endOfVarScope, parentLifetime, std::move(values), tokenlist, errorLogger, settings);
19691967
}
19701968
}
19711969
// Constructor

0 commit comments

Comments
 (0)