Refactoring: use range for loop, early continue

This commit is contained in:
Daniel Marjamäki 2018-04-27 23:04:48 +02:00
parent f336c2efe7
commit c80c44ab20
1 changed files with 15 additions and 15 deletions

View File

@ -283,22 +283,22 @@ void CheckClass::copyconstructors()
for (const Scope * scope : symbolDatabase->classAndStructScopes) { for (const Scope * scope : symbolDatabase->classAndStructScopes) {
std::map<unsigned int, const Token*> allocatedVars; std::map<unsigned int, const Token*> allocatedVars;
for (std::list<Function>::const_iterator func = scope->functionList.begin(); func != scope->functionList.end(); ++func) { for (const Function &func : scope->functionList) {
if (func->type == Function::eConstructor && func->functionScope) { if (func.type != Function::eConstructor || !func.functionScope)
const Token* tok = func->functionScope->classDef->linkAt(1); continue;
for (const Token* const end = func->functionScope->bodyStart; tok != end; tok = tok->next()) { const Token* tok = func.token->linkAt(1);
if (Token::Match(tok, "%var% ( new|malloc|g_malloc|g_try_malloc|realloc|g_realloc|g_try_realloc")) { for (const Token* const end = func.functionScope->bodyStart; tok != end; tok = tok->next()) {
const Variable* var = tok->variable(); if (Token::Match(tok, "%var% ( new|malloc|g_malloc|g_try_malloc|realloc|g_realloc|g_try_realloc")) {
if (var && var->isPointer() && var->scope() == scope) const Variable* var = tok->variable();
allocatedVars[tok->varId()] = tok; if (var && var->isPointer() && var->scope() == scope)
} allocatedVars[tok->varId()] = tok;
} }
for (const Token* const end = func->functionScope->bodyEnd; tok != end; tok = tok->next()) { }
if (Token::Match(tok, "%var% = new|malloc|g_malloc|g_try_malloc|realloc|g_realloc|g_try_realloc")) { for (const Token* const end = func.functionScope->bodyEnd; tok != end; tok = tok->next()) {
const Variable* var = tok->variable(); if (Token::Match(tok, "%var% = new|malloc|g_malloc|g_try_malloc|realloc|g_realloc|g_try_realloc")) {
if (var && var->isPointer() && var->scope() == scope && !var->isStatic()) const Variable* var = tok->variable();
allocatedVars[tok->varId()] = tok; if (var && var->isPointer() && var->scope() == scope && !var->isStatic())
} allocatedVars[tok->varId()] = tok;
} }
} }
} }