Skip to content

Commit 0729894

Browse files
committed
valueflow.cpp: avoid unnecessary copies with valueFlowForwardConst()
1 parent 14f1242 commit 0729894

1 file changed

Lines changed: 9 additions & 19 deletions

File tree

lib/valueflow.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3901,16 +3901,15 @@ template<class ContainerOfValue>
39013901
static void valueFlowForwardConst(Token* start,
39023902
const Token* end,
39033903
const Variable* var,
3904-
const ContainerOfValue& values,
3905-
const Settings& settings,
3906-
int /*unused*/ = 0)
3904+
ContainerOfValue values,
3905+
const Settings& settings)
39073906
{
39083907
if (!precedes(start, end))
39093908
throw InternalError(var->nameToken(), "valueFlowForwardConst: start token does not precede the end token.");
39103909
for (Token* tok = start; tok != end; tok = tok->next()) {
39113910
if (tok->varId() == var->declarationId()) {
3912-
for (const ValueFlow::Value& value : values)
3913-
setTokenValue(tok, value, settings);
3911+
for (ValueFlow::Value& value : values)
3912+
setTokenValue(tok, std::move(value), settings);
39143913
} else {
39153914
[&] {
39163915
// Follow references
@@ -3919,7 +3918,7 @@ static void valueFlowForwardConst(Token* start,
39193918
return ref.token->varId() == var->declarationId();
39203919
});
39213920
if (it != refs.end()) {
3922-
for (ValueFlow::Value value : values) {
3921+
for (ValueFlow::Value& value : values) {
39233922
if (refs.size() > 1)
39243923
value.setInconclusive();
39253924
value.errorPath.insert(value.errorPath.end(), it->errors.cbegin(), it->errors.cend());
@@ -3935,7 +3934,7 @@ static void valueFlowForwardConst(Token* start,
39353934
continue;
39363935
if (v.tokvalue->varId() != var->declarationId())
39373936
continue;
3938-
for (ValueFlow::Value value : values) {
3937+
for (ValueFlow::Value& value : values) {
39393938
if (!v.isKnown() && value.isImpossible())
39403939
continue;
39413940
if (v.intvalue != 0) {
@@ -3955,15 +3954,6 @@ static void valueFlowForwardConst(Token* start,
39553954
}
39563955
}
39573956

3958-
static void valueFlowForwardConst(Token* start,
3959-
const Token* end,
3960-
const Variable* var,
3961-
const std::initializer_list<ValueFlow::Value>& values,
3962-
const Settings& settings)
3963-
{
3964-
valueFlowForwardConst(start, end, var, values, settings, 0);
3965-
}
3966-
39673957
static ValueFlow::Value::Bound findVarBound(const Variable* var,
39683958
const Token* start,
39693959
const Token* end,
@@ -4091,7 +4081,7 @@ static void valueFlowForwardAssign(Token* const tok,
40914081
});
40924082
std::list<ValueFlow::Value> constValues;
40934083
constValues.splice(constValues.end(), values, it, values.end());
4094-
valueFlowForwardConst(nextExpression, endOfVarScope, expr->variable(), constValues, settings);
4084+
valueFlowForwardConst(nextExpression, endOfVarScope, expr->variable(), std::move(constValues), settings);
40954085
}
40964086
if (isInitialVarAssign(expr)) {
40974087
// Check if variable is only incremented or decremented
@@ -4107,7 +4097,7 @@ static void valueFlowForwardAssign(Token* const tok,
41074097
value.bound = b;
41084098
value.invertRange();
41094099
value.setImpossible();
4110-
valueFlowForwardConst(nextExpression, endOfVarScope, expr->variable(), {std::move(value)}, settings);
4100+
valueFlowForwardConst(nextExpression, endOfVarScope, expr->variable(), std::list<ValueFlow::Value>{std::move(value)}, settings);
41114101
}
41124102
}
41134103
}
@@ -6675,7 +6665,7 @@ static void valueFlowContainerSetTokValue(const TokenList& tokenlist, ErrorLogge
66756665
value.setKnown();
66766666
Token* start = initList->link() ? initList->link() : initList->next();
66776667
if (tok->variable() && tok->variable()->isConst()) {
6678-
valueFlowForwardConst(start, tok->variable()->scope()->bodyEnd, tok->variable(), {std::move(value)}, settings);
6668+
valueFlowForwardConst(start, tok->variable()->scope()->bodyEnd, tok->variable(), std::list<ValueFlow::Value>{std::move(value)}, settings);
66796669
} else {
66806670
valueFlowForward(start, tok, std::move(value), tokenlist, errorLogger, settings);
66816671
}

0 commit comments

Comments
 (0)