avoid unnecessary creation of lists in SingleValueFlowForwardAnalyzer.isAlias() and MultiValueFlowForwardAnalyzer.isAlias() (#2586)

Comparing before and after (Ir per call) when scanning the Cppcheck source:
SingleValueFlowForwardAnalyzer.isAlias()
1246 -> 1101
MultiValueFlowForwardAnalyzer.isAlias()
4202 -> 1617
This commit is contained in:
Oliver Stöneberg 2020-04-03 09:25:21 +02:00 committed by GitHub
parent 85b050acdf
commit 8968edeabd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -2381,12 +2381,13 @@ struct SingleValueFlowForwardAnalyzer : ValueFlowForwardAnalyzer {
virtual bool isAlias(const Token* tok) const OVERRIDE {
if (value.isLifetimeValue())
return false;
const std::list<ValueFlow::Value> vals{value};
for (const auto& p:getVars()) {
nonneg int varid = p.first;
const Variable* var = p.second;
if (tok->varId() == varid)
return true;
if (isAliasOf(var, tok, varid, {value}))
if (isAliasOf(var, tok, varid, vals))
return true;
}
return false;
@ -4612,13 +4613,14 @@ struct MultiValueFlowForwardAnalyzer : ValueFlowForwardAnalyzer {
}
virtual bool isAlias(const Token* tok) const OVERRIDE {
std::list<ValueFlow::Value> vals;
std::transform(values.begin(), values.end(), std::back_inserter(vals), SelectMapValues{});
for (const auto& p:getVars()) {
nonneg int varid = p.first;
const Variable* var = p.second;
if (tok->varId() == varid)
return true;
std::list<ValueFlow::Value> vals;
std::transform(values.begin(), values.end(), std::back_inserter(vals), SelectMapValues{});
if (isAliasOf(var, tok, varid, vals))
return true;
}