Skip to content

Commit 4316884

Browse files
authored
valueflow.cpp: avoid some copies related to ErrorPath (#4160)
1 parent ebe8dc2 commit 4316884

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

lib/valueflow.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,24 +2583,23 @@ struct ValueFlowAnalyzer : Analyzer {
25832583
tok->astParent()->astOperand2()->getKnownValue(ValueFlow::Value::ValueType::INT);
25842584
assert(rhsValue);
25852585
if (evalAssignment(*value, getAssign(tok->astParent(), d), *rhsValue)) {
2586-
const std::string info("Compound assignment '" + tok->astParent()->str() + "', assigned value is " +
2587-
value->infoString());
2586+
std::string info("Compound assignment '" + tok->astParent()->str() + "', assigned value is " +
2587+
value->infoString());
25882588
if (tok->astParent()->str() == "=")
25892589
value->errorPath.clear();
2590-
value->errorPath.emplace_back(tok, info);
2590+
value->errorPath.emplace_back(tok, std::move(info));
25912591
} else {
25922592
assert(false && "Writable value cannot be evaluated");
25932593
// TODO: Don't set to zero
25942594
value->intvalue = 0;
25952595
}
25962596
} else if (tok->astParent()->tokType() == Token::eIncDecOp) {
25972597
bool inc = tok->astParent()->str() == "++";
2598-
std::string opName(inc ? "incremented" : "decremented");
2598+
const std::string opName(inc ? "incremented" : "decremented");
25992599
if (d == Direction::Reverse)
26002600
inc = !inc;
26012601
value->intvalue += (inc ? 1 : -1);
2602-
const std::string info(tok->str() + " is " + opName + "', new value is " + value->infoString());
2603-
value->errorPath.emplace_back(tok, info);
2602+
value->errorPath.emplace_back(tok, tok->str() + " is " + opName + "', new value is " + value->infoString());
26042603
}
26052604
}
26062605

@@ -3985,6 +3984,7 @@ struct LifetimeStore {
39853984
const Token *tok2 = v.tokvalue;
39863985
ErrorPath er = v.errorPath;
39873986
const Variable *var = getLifetimeVariable(tok2, er);
3987+
// TODO: the inserted data is never used
39883988
er.insert(er.end(), errorPath.begin(), errorPath.end());
39893989
if (!var)
39903990
continue;
@@ -4532,7 +4532,7 @@ static void valueFlowLifetime(TokenList *tokenlist, SymbolDatabase*, ErrorLogger
45324532
else if (c == LifetimeCapture::ByValue)
45334533
value.lifetimeScope = ValueFlow::Value::LifetimeScope::ThisValue;
45344534
value.tokvalue = tok2;
4535-
value.errorPath.push_back({tok2, "Lambda captures the 'this' variable here."});
4535+
value.errorPath.emplace_back(tok2, "Lambda captures the 'this' variable here.");
45364536
value.lifetimeKind = ValueFlow::Value::LifetimeKind::Lambda;
45374537
capturedThis = true;
45384538
// Don't add the value a second time
@@ -7000,8 +7000,7 @@ static void valueFlowSwitchVariable(TokenList *tokenlist, SymbolDatabase* symbol
70007000
std::list<ValueFlow::Value> values;
70017001
values.emplace_back(MathLib::toLongNumber(tok->next()->str()));
70027002
values.back().condition = tok;
7003-
const std::string info("case " + tok->next()->str() + ": " + vartok->str() + " is " + tok->next()->str() + " here.");
7004-
values.back().errorPath.emplace_back(tok, info);
7003+
values.back().errorPath.emplace_back(tok, "case " + tok->next()->str() + ": " + vartok->str() + " is " + tok->next()->str() + " here.");
70057004
bool known = false;
70067005
if ((Token::simpleMatch(tok->previous(), "{") || Token::simpleMatch(tok->tokAt(-2), "break ;")) && !Token::Match(tok->tokAt(3), ";| case"))
70077006
known = true;
@@ -7012,8 +7011,7 @@ static void valueFlowSwitchVariable(TokenList *tokenlist, SymbolDatabase* symbol
70127011
tok = tok->next();
70137012
values.emplace_back(MathLib::toLongNumber(tok->next()->str()));
70147013
values.back().condition = tok;
7015-
const std::string info2("case " + tok->next()->str() + ": " + vartok->str() + " is " + tok->next()->str() + " here.");
7016-
values.back().errorPath.emplace_back(tok, info2);
7014+
values.back().errorPath.emplace_back(tok, "case " + tok->next()->str() + ": " + vartok->str() + " is " + tok->next()->str() + " here.");
70177015
}
70187016
for (std::list<ValueFlow::Value>::const_iterator val = values.begin(); val != values.end(); ++val) {
70197017
valueFlowReverse(tokenlist,

0 commit comments

Comments
 (0)