diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 7d8d572ca..30147b530 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -2227,9 +2227,9 @@ void CheckOther::checkComparisonOfFuncReturningBool() const SymbolDatabase * const symbolDatabase = _tokenizer->getSymbolDatabase(); - for (std::list::const_iterator scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) { - if (!scope->isExecutable()) - continue; + size_t functions = symbolDatabase->functionScopeList.size(); + for (size_t i = 0; i < functions; ++i) { + const Scope * scope = symbolDatabase->functionScopeList[i]; for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { if (tok->type() != Token::eComparisonOp || tok->str() == "==" || tok->str() == "!=") continue; @@ -2307,9 +2307,9 @@ void CheckOther::checkComparisonOfBoolWithBool() const SymbolDatabase* const symbolDatabase = _tokenizer->getSymbolDatabase(); - for (std::list::const_iterator scope = symbolDatabase->scopeList.begin(); scope != symbolDatabase->scopeList.end(); ++scope) { - if (!scope->isExecutable()) - continue; + size_t functions = symbolDatabase->functionScopeList.size(); + for (size_t i = 0; i < functions; ++i) { + const Scope * scope = symbolDatabase->functionScopeList[i]; for (const Token* tok = scope->classStart->next(); tok != scope->classEnd; tok = tok->next()) { if (tok->type() != Token::eComparisonOp || tok->str() == "==" || tok->str() == "!=") continue; diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index c2233a0c6..8a3d48b92 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -623,6 +623,12 @@ SymbolDatabase::SymbolDatabase(const Tokenizer *tokenizer, const Settings *setti } } + // fill in function list + for (it = scopeList.begin(); it != scopeList.end(); ++it) { + if (it->type == Scope::eFunction) + functionScopeList.push_back(&*it); + } + // determine if user defined type needs initialization unsigned int unknowns = 0; // stop checking when there are no unknowns unsigned int retry = 0; // bail if we don't resolve all the variable types for some reason diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index 929007f76..0e40fd515 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -560,6 +560,9 @@ public: /** @brief Information about all namespaces/classes/structrues */ std::list scopeList; + /** @brief Fast access to function scopes */ + std::vector functionScopeList; + /** * @brief find a variable type if it's a user defined type * @param start scope to start looking in