Moved duplicate code into function in CheckOther::checkRedundantAssignment()
This commit is contained in:
parent
318d80be08
commit
2be2738c6e
|
@ -614,6 +614,19 @@ void CheckOther::sizeofForPointerError(const Token *tok, const std::string &varn
|
||||||
// Detect redundant assignments: x = 0; x = 4;
|
// Detect redundant assignments: x = 0; x = 4;
|
||||||
//---------------------------------------------------------------------------
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
static void eraseNotLocalArg(std::map<unsigned int, const Token*>& container, const SymbolDatabase* symbolDatabase)
|
||||||
|
{
|
||||||
|
for (std::map<unsigned int, const Token*>::iterator i = container.begin(); i != container.end();) {
|
||||||
|
const Variable* var = symbolDatabase->getVariableFromVarId(i->first);
|
||||||
|
if (!var || (!var->isLocal() && !var->isArgument())) {
|
||||||
|
container.erase(i++);
|
||||||
|
if (i == container.end())
|
||||||
|
break;
|
||||||
|
} else
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CheckOther::checkRedundantAssignment()
|
void CheckOther::checkRedundantAssignment()
|
||||||
{
|
{
|
||||||
if (!_settings->isEnabled("performance"))
|
if (!_settings->isEnabled("performance"))
|
||||||
|
@ -702,23 +715,8 @@ void CheckOther::checkRedundantAssignment()
|
||||||
const Token* funcEnd = func->functionScope->classEnd;
|
const Token* funcEnd = func->functionScope->classEnd;
|
||||||
bool noreturn;
|
bool noreturn;
|
||||||
if (!_tokenizer->IsScopeNoReturn(funcEnd, &noreturn) && !noreturn) {
|
if (!_tokenizer->IsScopeNoReturn(funcEnd, &noreturn) && !noreturn) {
|
||||||
for (std::map<unsigned int, const Token*>::iterator i = varAssignments.begin(); i != varAssignments.end(); ++i) {
|
eraseNotLocalArg(varAssignments, symbolDatabase);
|
||||||
const Variable* var = symbolDatabase->getVariableFromVarId(i->first);
|
eraseNotLocalArg(memAssignments, symbolDatabase);
|
||||||
if (!var || (!var->isLocal() && !var->isArgument())) {
|
|
||||||
varAssignments.erase(i++);
|
|
||||||
if (i == varAssignments.end())
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (std::map<unsigned int, const Token*>::iterator i = memAssignments.begin(); i != memAssignments.end(); ++i) {
|
|
||||||
const Variable* var = symbolDatabase->getVariableFromVarId(i->first);
|
|
||||||
if (!var || (!var->isLocal() && !var->isArgument())) {
|
|
||||||
memAssignments.erase(i++);
|
|
||||||
if (i == memAssignments.end())
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
varAssignments.clear();
|
varAssignments.clear();
|
||||||
memAssignments.clear();
|
memAssignments.clear();
|
||||||
|
|
Loading…
Reference in New Issue