Commit bf892854 authored by Igor Kushnir's avatar Igor Kushnir
Browse files

Deduplicate ItemRepositoryFor<Context>::init()

Almost every specialization of ItemRepositoryFor class template defines
a public static member function init() with the same trivial definition.
Replace the duplicated init() with LockedItemRepository::initialize().

The refactoring reveals that ItemRepositoryFor<IndexedString>::init()
was unused. init() was also missing from item repositories for
IndexedIdentifier, IndexedQualifiedIdentifier and
IndexedInstantiationInformation. I don't know if this lack of
initialization of Indexed* repositories is fine or a potential bug.
parent d4023711
Pipeline #221303 passed with stage
in 17 minutes and 15 seconds
......@@ -174,16 +174,11 @@ class ItemRepositoryFor<CodeModel>
static CodeModelRepo repo(QStringLiteral("Code Model"), &mutex);
return repo;
}
public:
static void init()
{
repo();
}
};
CodeModel::CodeModel()
{
ItemRepositoryFor<CodeModel>::init();
LockedItemRepository::initialize<CodeModel>();
}
void CodeModel::addItem(const IndexedString& file, const IndexedQualifiedIdentifier& id, CodeModelItem::Kind kind)
......
......@@ -64,14 +64,11 @@ class ItemRepositoryFor<DeclarationComment>
static Repositories::StringRepository repo(QStringLiteral("Comment Repository"), &mutex);
return repo;
}
public:
static void init() { repo(); }
};
void initDeclarationRepositories()
{
ItemRepositoryFor<DeclarationComment>::init();
LockedItemRepository::initialize<DeclarationComment>();
}
Declaration::Kind Declaration::kind() const
......
......@@ -159,14 +159,11 @@ class ItemRepositoryFor<Definitions>
static DefinitionsRepo repo { QStringLiteral("Definition Map"), &mutex };
return repo;
}
public:
static void init() { repo(); }
};
Definitions::Definitions()
{
ItemRepositoryFor<Definitions>::init();
LockedItemRepository::initialize<Definitions>();
}
void Definitions::addDefinition(const DeclarationId& id, const IndexedDeclaration& definition)
......
......@@ -307,9 +307,6 @@ class ItemRepositoryFor<EnvironmentInformationList>
static EnvironmentInformationListRepo repo(QStringLiteral("Environment Lists"), &mutex);
return repo;
}
public:
static void init() { repo(); }
};
/// Maps top-context-indices to environment-information item.
......@@ -327,9 +324,6 @@ class ItemRepositoryFor<EnvironmentInformation>
static EnvironmentInformationRepo repo(QStringLiteral("Environment Information"), &mutex);
return repo;
}
public:
static void init() { repo(); }
};
class DUChainPrivate;
......@@ -1296,8 +1290,8 @@ void DUChain::initialize()
// read. See https://bugs.kde.org/show_bug.cgi?id=250779
RecursiveImportRepository::repository();
ItemRepositoryFor<EnvironmentInformationList>::init();
ItemRepositoryFor<EnvironmentInformation>::init();
LockedItemRepository::initialize<EnvironmentInformationList>();
LockedItemRepository::initialize<EnvironmentInformation>();
// similar to above, see https://bugs.kde.org/show_bug.cgi?id=255323
initDeclarationRepositories();
......
......@@ -115,14 +115,11 @@ class ItemRepositoryFor<Importers>
static ImportersRepo repo { QStringLiteral("Importer Map"), &mutex };
return repo;
}
public:
static void init() { repo(); }
};
Importers::Importers()
{
ItemRepositoryFor<Importers>::init();
LockedItemRepository::initialize<Importers>();
}
void Importers::addImporter(const DeclarationId& id, const IndexedDUContext& use)
......
......@@ -212,9 +212,6 @@ class ItemRepositoryFor<PersistentSymbolTable>
static PersistentSymbolTableRepo repo { QStringLiteral("Persistent Declaration Table"), &mutex };
return repo;
}
public:
static void init() { repo(); }
};
void PersistentSymbolTable::clearCache()
......@@ -230,7 +227,7 @@ PersistentSymbolTable::PersistentSymbolTable()
// PersistentSymbolTableRepo::importsCache uses RecursiveImportCacheRepository, so the cache repository must be
// destroyed after and therefore created before the persistent symbol table repository.
RecursiveImportCacheRepository::repository();
ItemRepositoryFor<PersistentSymbolTable>::init();
LockedItemRepository::initialize<PersistentSymbolTable>();
}
PersistentSymbolTable::~PersistentSymbolTable() = default;
......
......@@ -103,14 +103,11 @@ class ItemRepositoryFor<AbstractType>
typeRepositoryMutex());
return *manager.repository();
}
public:
static void init() { repo(); }
};
void initTypeRepository()
{
ItemRepositoryFor<AbstractType>::init();
LockedItemRepository::initialize<AbstractType>();
}
uint TypeRepository::indexForType(const AbstractType::Ptr& input)
......
......@@ -114,14 +114,11 @@ class ItemRepositoryFor<Uses>
static UsesRepo repo { QStringLiteral("Use Map"), &mutex };
return repo;
}
public:
static void init() { repo(); }
};
Uses::Uses()
{
ItemRepositoryFor<Uses>::init();
LockedItemRepository::initialize<Uses>();
}
void Uses::addUse(const DeclarationId& id, const IndexedTopDUContext& use)
......
......@@ -149,9 +149,6 @@ class ItemRepositoryFor<IndexedString>
&mutex };
return *manager.repository();
}
public:
static void init() { repo(); }
};
}
......
......@@ -2310,6 +2310,12 @@ struct LockedItemRepository {
QMutexLocker lock(repo.mutex());
return op(repo);
}
template<typename Context>
static void initialize()
{
ItemRepositoryFor<Context>::repo();
}
};
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment