diff --git a/lib/checkclass.cpp b/lib/checkclass.cpp index 2666e7c85..aa192b300 100644 --- a/lib/checkclass.cpp +++ b/lib/checkclass.cpp @@ -941,8 +941,9 @@ static bool checkFunctionUsage(const Function *privfunc, const Scope* scope) return true; } - for (std::list::const_iterator i = scope->definedTypes.begin(); i != scope->definedTypes.end(); ++i) { - const Type *type = *i; + const std::map::const_iterator end = scope->definedTypesMap.end(); + for (std::map::const_iterator iter = scope->definedTypesMap.begin(); iter != end; ++ iter) { + const Type *type = (*iter).second; if (type->enclosingScope == scope && checkFunctionUsage(privfunc, type->classScope)) return true; } diff --git a/lib/symboldatabase.cpp b/lib/symboldatabase.cpp index a84f81301..6e258c211 100644 --- a/lib/symboldatabase.cpp +++ b/lib/symboldatabase.cpp @@ -171,7 +171,7 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() if (!new_type) { typeList.push_back(Type(new_scope->classDef, new_scope, scope)); new_type = &typeList.back(); - scope->definedTypes.push_back(new_type); + scope->definedTypesMap[new_type->name()] = new_type; } else new_type->classScope = new_scope; new_scope->definedType = new_type; @@ -249,7 +249,8 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() if (!findType(tok->next(), scope)) { // fill typeList.. typeList.push_back(Type(tok, nullptr, scope)); - scope->definedTypes.push_back(&typeList.back()); + Type* new_type = &typeList.back(); + scope->definedTypesMap[new_type->name()] = new_type; } tok = tok->tokAt(2); } @@ -290,8 +291,11 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() } typeList.push_back(Type(tok, new_scope, scope)); - new_scope->definedType = &typeList.back(); - scope->definedTypes.push_back(&typeList.back()); + { + Type* new_type = &typeList.back(); + new_scope->definedType = new_type; + scope->definedTypesMap[new_type->name()] = new_type; + } scope->addVariable(varNameTok, tok, tok, access[scope], new_scope->definedType, scope, &_settings->library); @@ -328,8 +332,11 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() new_scope->classEnd = tok2->link(); typeList.push_back(Type(tok, new_scope, scope)); - new_scope->definedType = &typeList.back(); - scope->definedTypes.push_back(&typeList.back()); + { + Type* new_type = &typeList.back(); + new_scope->definedType = new_type; + scope->definedTypesMap[new_type->name()] = new_type; + } // make sure we have valid code if (!new_scope->classEnd) { @@ -347,7 +354,8 @@ void SymbolDatabase::createSymbolDatabaseFindAllScopes() // forward declared enum else if (Token::Match(tok, "enum class| %name% ;") || Token::Match(tok, "enum class| %name% : %name% ;")) { typeList.push_back(Type(tok, nullptr, scope)); - scope->definedTypes.push_back(&typeList.back()); + Type* new_type = &typeList.back(); + scope->definedTypesMap[new_type->name()] = new_type; tok = tok->tokAt(2); } @@ -4340,13 +4348,16 @@ const Scope *Scope::findRecordInNestedList(const std::string & name) const const Type* Scope::findType(const std::string & name) const { - std::list::const_iterator it; + auto it = definedTypesMap.find(name); - for (it = definedTypes.begin(); it != definedTypes.end(); ++it) { - if ((*it)->name() == name) - return (*it); + if (definedTypesMap.end() == it) + { + return nullptr; + } + else + { + return (*it).second; } - return nullptr; } //--------------------------------------------------------------------------- diff --git a/lib/symboldatabase.h b/lib/symboldatabase.h index b822ad63c..7b494db88 100644 --- a/lib/symboldatabase.h +++ b/lib/symboldatabase.h @@ -903,7 +903,7 @@ public: std::list usingList; ScopeType type; Type* definedType; - std::list definedTypes; + std::map definedTypesMap; // function specific fields const Scope *functionOf; // scope this function belongs to