Store the defined types in a map, for faster lookup

This commit is contained in:
Florin Iucha 2017-10-14 20:53:41 -04:00 committed by PKEuS
parent cccf035535
commit 6e737082da
3 changed files with 27 additions and 15 deletions

View File

@ -941,8 +941,9 @@ static bool checkFunctionUsage(const Function *privfunc, const Scope* scope)
return true;
}
for (std::list<Type*>::const_iterator i = scope->definedTypes.begin(); i != scope->definedTypes.end(); ++i) {
const Type *type = *i;
const std::map<std::string, Type*>::const_iterator end = scope->definedTypesMap.end();
for (std::map<std::string, Type*>::const_iterator iter = scope->definedTypesMap.begin(); iter != end; ++ iter) {
const Type *type = (*iter).second;
if (type->enclosingScope == scope && checkFunctionUsage(privfunc, type->classScope))
return true;
}

View File

@ -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<Type*>::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;
}
//---------------------------------------------------------------------------

View File

@ -903,7 +903,7 @@ public:
std::list<UsingInfo> usingList;
ScopeType type;
Type* definedType;
std::list<Type*> definedTypes;
std::map<std::string, Type*> definedTypesMap;
// function specific fields
const Scope *functionOf; // scope this function belongs to