From c80c44ab204980e136d9352979a22c5b840822dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 27 Apr 2018 23:04:48 +0200 Subject: [PATCH] Refactoring: use range for loop, early continue --- lib/checkclass.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 625eda294..295d9ea06 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -283,22 +283,22 @@ void CheckClass::copyconstructors() for (const Scope * scope : symbolDatabase->classAndStructScopes) { std::map allocatedVars; - for (std::list::const_iterator func = scope->functionList.begin(); func != scope->functionList.end(); ++func) { - if (func->type == Function::eConstructor && func->functionScope) { - const Token* tok = func->functionScope->classDef->linkAt(1); - for (const Token* const end = func->functionScope->bodyStart; tok != end; tok = tok->next()) { - if (Token::Match(tok, "%var% ( new|malloc|g_malloc|g_try_malloc|realloc|g_realloc|g_try_realloc")) { - const Variable* var = tok->variable(); - if (var && var->isPointer() && var->scope() == scope) - allocatedVars[tok->varId()] = tok; - } + for (const Function &func : scope->functionList) { + if (func.type != Function::eConstructor || !func.functionScope) + continue; + const Token* tok = func.token->linkAt(1); + for (const Token* const end = func.functionScope->bodyStart; tok != end; tok = tok->next()) { + if (Token::Match(tok, "%var% ( new|malloc|g_malloc|g_try_malloc|realloc|g_realloc|g_try_realloc")) { + const Variable* var = tok->variable(); + 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")) { - const Variable* var = tok->variable(); - if (var && var->isPointer() && var->scope() == scope && !var->isStatic()) - 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")) { + const Variable* var = tok->variable(); + if (var && var->isPointer() && var->scope() == scope && !var->isStatic()) + allocatedVars[tok->varId()] = tok; } } }