Refactoring: Use range for loops in CheckClass

This commit is contained in:
Daniel Marjamäki 2018-04-23 07:51:28 +02:00
parent e08683c009
commit 42c54f12fe
1 changed files with 4 additions and 12 deletions

View File

@ -836,10 +836,7 @@ void CheckClass::initializationListUsage()
if (!_settings->isEnabled(Settings::PERFORMANCE)) if (!_settings->isEnabled(Settings::PERFORMANCE))
return; return;
const std::size_t functions = symbolDatabase->functionScopes.size(); for (const Scope *scope : symbolDatabase->functionScopes) {
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
// Check every constructor // Check every constructor
if (!scope->function || (!scope->function->isConstructor())) if (!scope->function || (!scope->function->isConstructor()))
continue; continue;
@ -1020,9 +1017,7 @@ static const Scope* findFunctionOf(const Scope* scope)
void CheckClass::checkMemset() void CheckClass::checkMemset()
{ {
const bool printWarnings = _settings->isEnabled(Settings::WARNING); const bool printWarnings = _settings->isEnabled(Settings::WARNING);
const std::size_t functions = symbolDatabase->functionScopes.size(); for (const Scope *scope : symbolDatabase->functionScopes) {
for (std::size_t i = 0; i < functions; ++i) {
const Scope * scope = symbolDatabase->functionScopes[i];
for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) { for (const Token *tok = scope->classStart; tok && tok != scope->classEnd; tok = tok->next()) {
if (Token::Match(tok, "memset|memcpy|memmove (")) { if (Token::Match(tok, "memset|memcpy|memmove (")) {
const Token* arg1 = tok->tokAt(2); const Token* arg1 = tok->tokAt(2);
@ -2161,8 +2156,7 @@ void CheckClass::initializerListError(const Token *tok1, const Token *tok2, cons
void CheckClass::checkSelfInitialization() void CheckClass::checkSelfInitialization()
{ {
for (std::size_t i = 0; i < symbolDatabase->functionScopes.size(); ++i) { for (const Scope *scope : symbolDatabase->functionScopes) {
const Scope* scope = symbolDatabase->functionScopes[i];
const Function* function = scope->function; const Function* function = scope->function;
if (!function || !function->isConstructor()) if (!function || !function->isConstructor())
continue; continue;
@ -2193,10 +2187,8 @@ void CheckClass::checkVirtualFunctionCallInConstructor()
{ {
if (! _settings->isEnabled(Settings::WARNING)) if (! _settings->isEnabled(Settings::WARNING))
return; return;
const std::size_t functions = symbolDatabase->functionScopes.size();
std::map<const Function *, std::list<const Token *> > virtualFunctionCallsMap; std::map<const Function *, std::list<const Token *> > virtualFunctionCallsMap;
for (std::size_t i = 0; i < functions; ++i) { for (const Scope *scope : symbolDatabase->functionScopes) {
const Scope * scope = symbolDatabase->functionScopes[i];
if (scope->function == nullptr || !scope->function->hasBody() || if (scope->function == nullptr || !scope->function->hasBody() ||
!(scope->function->isConstructor() || !(scope->function->isConstructor() ||
scope->function->isDestructor())) scope->function->isDestructor()))