Sqlite: Add compound id

Saving the source context id as part of the source id simplyfies file
path handling. It is now very easy to see if a two source ids have the
same source context id.

Change-Id: I6c86942d9f026fc047c49bbde3fffd6af14d81de
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2024-08-01 14:14:18 +02:00
parent 0d571b5e95
commit 2ae8ae75af
24 changed files with 392 additions and 501 deletions

View File

@@ -15,7 +15,7 @@ enum class BasicIdType {
Type,
PropertyType,
PropertyDeclaration,
Source,
SourceName,
SourceContext,
StorageCacheIndex,
FunctionDeclaration,
@@ -51,10 +51,10 @@ using SourceContextIds = std::vector<SourceContextId>;
template<std::size_t size>
using SmallSourceContextIds = QVarLengthArray<SourceContextId, size>;
using SourceId = Sqlite::BasicId<BasicIdType::Source, int>;
using SourceIds = std::vector<SourceId>;
using SourceNameId = Sqlite::BasicId<BasicIdType::SourceName, int>;
using SourceNameIds = std::vector<SourceNameId>;
template<std::size_t size>
using SmallSourceIds = QVarLengthArray<SourceId, size>;
using SmallSourceNameIds = QVarLengthArray<SourceNameId, size>;
using ModuleId = Sqlite::BasicId<BasicIdType::Module, int>;
using ModuleIds = std::vector<ModuleId>;
@@ -75,4 +75,9 @@ using ExportedTypeNameIds = std::vector<ExportedTypeNameId>;
using ModuleExportedImportId = Sqlite::BasicId<BasicIdType::ModuleExportedImport>;
using ModuleExportedImportIds = std::vector<ModuleExportedImportId>;
using SourceId = Sqlite::CompoundBasicId<BasicIdType::SourceName, BasicIdType::SourceContext>;
using SourceIds = std::vector<SourceId>;
template<std::size_t size>
using SmallSourceIds = QVarLengthArray<SourceId, size>;
} // namespace QmlDesigner

View File

@@ -81,16 +81,14 @@ struct ProjectStorage::Statements
"SELECT sourceContextPath, sourceContextId FROM sourceContexts", database};
Sqlite::WriteStatement<1> insertIntoSourceContextsStatement{
"INSERT INTO sourceContexts(sourceContextPath) VALUES (?)", database};
mutable Sqlite::ReadStatement<1, 2> selectSourceIdFromSourcesBySourceContextIdAndSourceNameStatement{
"SELECT sourceId FROM sources WHERE sourceContextId = ? AND sourceName = ?", database};
mutable Sqlite::ReadStatement<2, 1> selectSourceNameAndSourceContextIdFromSourcesBySourceIdStatement{
"SELECT sourceName, sourceContextId FROM sources WHERE sourceId = ?", database};
mutable Sqlite::ReadStatement<1, 1> selectSourceContextIdFromSourcesBySourceIdStatement{
"SELECT sourceContextId FROM sources WHERE sourceId = ?", database};
Sqlite::WriteStatement<2> insertIntoSourcesStatement{
"INSERT INTO sources(sourceContextId, sourceName) VALUES (?,?)", database};
mutable Sqlite::ReadStatement<3> selectAllSourcesStatement{
"SELECT sourceName, sourceContextId, sourceId FROM sources", database};
mutable Sqlite::ReadStatement<1, 1> selectSourceNameIdFromSourceNamesBySourceNameStatement{
"SELECT sourceNameId FROM sourceNames WHERE sourceName = ?", database};
mutable Sqlite::ReadStatement<1, 1> selectSourceNameFromSourceNamesBySourceNameIdStatement{
"SELECT sourceName FROM sourceNames WHERE sourceNameId = ?", database};
Sqlite::WriteStatement<1> insertIntoSourcesStatement{
"INSERT INTO sourceNames(sourceName) VALUES (?)", database};
mutable Sqlite::ReadStatement<2> selectAllSourcesStatement{
"SELECT sourceName, sourceNameId FROM sourceNames", database};
mutable Sqlite::ReadStatement<8, 1> selectTypeByTypeIdStatement{
"SELECT sourceId, t.name, t.typeId, prototypeId, extensionId, traits, annotationTraits, "
"pd.name "
@@ -621,7 +619,7 @@ struct ProjectStorage::Statements
"ORDER BY itn.kind, etn.majorVersion DESC NULLS FIRST, etn.minorVersion DESC NULLS FIRST "
"LIMIT 1",
database};
Sqlite::WriteStatement<0> deleteAllSourcesStatement{"DELETE FROM sources", database};
Sqlite::WriteStatement<0> deleteAllSourceNamesStatement{"DELETE FROM sourceNames", database};
Sqlite::WriteStatement<0> deleteAllSourceContextsStatement{"DELETE FROM sourceContexts", database};
mutable Sqlite::ReadStatement<6, 1> selectExportedTypesForSourceIdsStatement{
"SELECT moduleId, name, ifnull(majorVersion, -1), ifnull(minorVersion, -1), typeId, "
@@ -897,7 +895,7 @@ public:
if (!isInitialized) {
auto moduleIdColumn = createModulesTable(database);
createSourceContextsTable(database);
createSourcesTable(database);
createSourceNamesTable(database);
createTypesAndePropertyDeclarationsTables(database, moduleIdColumn);
createExportedTypeNamesTable(database, moduleIdColumn);
createImportedTypeNamesTable(database);
@@ -927,22 +925,14 @@ public:
table.initialize(database);
}
void createSourcesTable(Database &database)
void createSourceNamesTable(Database &database)
{
Sqlite::StrictTable table;
table.setUseIfNotExists(true);
table.setName("sources");
table.addColumn("sourceId", Sqlite::StrictColumnType::Integer, {Sqlite::PrimaryKey{}});
const auto &sourceContextIdColumn = table.addColumn(
"sourceContextId",
Sqlite::StrictColumnType::Integer,
{Sqlite::NotNull{},
Sqlite::ForeignKey{"sourceContexts",
"sourceContextId",
Sqlite::ForeignKeyAction::NoAction,
Sqlite::ForeignKeyAction::Cascade}});
table.setName("sourceNames");
table.addColumn("sourceNameId", Sqlite::StrictColumnType::Integer, {Sqlite::PrimaryKey{}});
const auto &sourceNameColumn = table.addColumn("sourceName", Sqlite::StrictColumnType::Text);
table.addUniqueIndex({sourceContextIdColumn, sourceNameColumn});
table.addUniqueIndex({sourceNameColumn});
table.initialize(database);
}
@@ -1217,13 +1207,7 @@ public:
Sqlite::StrictTable table;
table.setUseIfNotExists(true);
table.setName("fileStatuses");
table.addColumn("sourceId",
Sqlite::StrictColumnType::Integer,
{Sqlite::PrimaryKey{},
Sqlite::ForeignKey{"sources",
"sourceId",
Sqlite::ForeignKeyAction::NoAction,
Sqlite::ForeignKeyAction::Cascade}});
table.addColumn("sourceId", Sqlite::StrictColumnType::Integer, {Sqlite::PrimaryKey{}});
table.addColumn("size", Sqlite::StrictColumnType::Integer);
table.addColumn("lastModified", Sqlite::StrictColumnType::Integer);
@@ -2193,89 +2177,66 @@ Cache::SourceContexts ProjectStorage::fetchAllSourceContexts() const
return s->selectAllSourceContextsStatement.valuesWithTransaction<Cache::SourceContext, 128>();
}
SourceId ProjectStorage::fetchSourceId(SourceContextId sourceContextId,
Utils::SmallStringView sourceName)
SourceNameId ProjectStorage::fetchSourceNameId(Utils::SmallStringView sourceName)
{
using NanotraceHR::keyValue;
NanotraceHR::Tracer tracer{"fetch source id"_t,
projectStorageCategory(),
keyValue("source context id", sourceContextId),
keyValue("source name", sourceName)};
auto sourceId = Sqlite::withDeferredTransaction(database, [&] {
return fetchSourceIdUnguarded(sourceContextId, sourceName);
auto sourceNameId = Sqlite::withDeferredTransaction(database, [&] {
return fetchSourceNameIdUnguarded(sourceName);
});
tracer.end(keyValue("source id", sourceId));
tracer.end(keyValue("source name id", sourceNameId));
return sourceId;
return sourceNameId;
}
Cache::SourceNameAndSourceContextId ProjectStorage::fetchSourceNameAndSourceContextId(SourceId sourceId) const
Utils::SmallString ProjectStorage::fetchSourceName(SourceNameId sourceNameId) const
{
using NanotraceHR::keyValue;
NanotraceHR::Tracer tracer{"fetch source name and source context id"_t,
projectStorageCategory(),
keyValue("source id", sourceId)};
keyValue("source name id", sourceNameId)};
auto value = s->selectSourceNameAndSourceContextIdFromSourcesBySourceIdStatement
.valueWithTransaction<Cache::SourceNameAndSourceContextId>(sourceId);
auto sourceName = s->selectSourceNameFromSourceNamesBySourceNameIdStatement
.valueWithTransaction<Utils::SmallString>(sourceNameId);
if (!value.sourceContextId)
throw SourceIdDoesNotExists();
if (sourceName.empty())
throw SourceNameIdDoesNotExists();
tracer.end(keyValue("source name", value.sourceName),
keyValue("source context id", value.sourceContextId));
tracer.end(keyValue("source name", sourceName));
return value;
return sourceName;
}
void ProjectStorage::clearSources()
{
Sqlite::withImmediateTransaction(database, [&] {
s->deleteAllSourceContextsStatement.execute();
s->deleteAllSourcesStatement.execute();
s->deleteAllSourceNamesStatement.execute();
});
}
SourceContextId ProjectStorage::fetchSourceContextId(SourceId sourceId) const
{
using NanotraceHR::keyValue;
NanotraceHR::Tracer tracer{"fetch source context id"_t,
projectStorageCategory(),
keyValue("source id", sourceId)};
auto sourceContextId = s->selectSourceContextIdFromSourcesBySourceIdStatement
.valueWithTransaction<SourceContextId>(sourceId);
if (!sourceContextId)
throw SourceIdDoesNotExists();
tracer.end(keyValue("source context id", sourceContextId));
return sourceContextId;
}
Cache::Sources ProjectStorage::fetchAllSources() const
Cache::SourceNames ProjectStorage::fetchAllSourceNames() const
{
NanotraceHR::Tracer tracer{"fetch all sources"_t, projectStorageCategory()};
return s->selectAllSourcesStatement.valuesWithTransaction<Cache::Source, 1024>();
return s->selectAllSourcesStatement.valuesWithTransaction<Cache::SourceName, 1024>();
}
SourceId ProjectStorage::fetchSourceIdUnguarded(SourceContextId sourceContextId,
Utils::SmallStringView sourceName)
SourceNameId ProjectStorage::fetchSourceNameIdUnguarded(Utils::SmallStringView sourceName)
{
using NanotraceHR::keyValue;
NanotraceHR::Tracer tracer{"fetch source id unguarded"_t,
projectStorageCategory(),
keyValue("source context id", sourceContextId),
keyValue("source name", sourceName)};
auto sourceId = readSourceId(sourceContextId, sourceName);
auto sourceId = readSourceNameId(sourceName);
if (!sourceId)
sourceId = writeSourceId(sourceContextId, sourceName);
sourceId = writeSourceNameId(sourceName);
tracer.end(keyValue("source id", sourceId));
@@ -4908,39 +4869,35 @@ SourceContextId ProjectStorage::writeSourceContextId(Utils::SmallStringView sour
return sourceContextId;
}
SourceId ProjectStorage::writeSourceId(SourceContextId sourceContextId,
Utils::SmallStringView sourceName)
SourceNameId ProjectStorage::writeSourceNameId(Utils::SmallStringView sourceName)
{
using NanotraceHR::keyValue;
NanotraceHR::Tracer tracer{"write source id"_t,
projectStorageCategory(),
keyValue("source context id", sourceContextId),
keyValue("source name", sourceName)};
s->insertIntoSourcesStatement.write(sourceContextId, sourceName);
s->insertIntoSourcesStatement.write(sourceName);
auto sourceId = SourceId::create(static_cast<int>(database.lastInsertedRowId()));
auto sourceNameId = SourceNameId::create(static_cast<int>(database.lastInsertedRowId()));
tracer.end(keyValue("source id", sourceId));
tracer.end(keyValue("source name id", sourceNameId));
return sourceId;
return sourceNameId;
}
SourceId ProjectStorage::readSourceId(SourceContextId sourceContextId,
Utils::SmallStringView sourceName)
SourceNameId ProjectStorage::readSourceNameId(Utils::SmallStringView sourceName)
{
using NanotraceHR::keyValue;
NanotraceHR::Tracer tracer{"read source id"_t,
projectStorageCategory(),
keyValue("source context id", sourceContextId),
keyValue("source name", sourceName)};
auto sourceId = s->selectSourceIdFromSourcesBySourceContextIdAndSourceNameStatement
.value<SourceId>(sourceContextId, sourceName);
auto sourceNameId = s->selectSourceNameIdFromSourceNamesBySourceNameStatement.value<SourceNameId>(
sourceName);
tracer.end(keyValue("source id", sourceId));
tracer.end(keyValue("source id", sourceNameId));
return sourceId;
return sourceNameId;
}
Storage::Synchronization::ExportedTypes ProjectStorage::fetchExportedTypes(TypeId typeId)

View File

@@ -223,18 +223,15 @@ public:
Cache::SourceContexts fetchAllSourceContexts() const;
SourceId fetchSourceId(SourceContextId sourceContextId, Utils::SmallStringView sourceName);
SourceNameId fetchSourceNameId(Utils::SmallStringView sourceName);
Cache::SourceNameAndSourceContextId fetchSourceNameAndSourceContextId(SourceId sourceId) const;
Utils::SmallString fetchSourceName(SourceNameId sourceId) const;
void clearSources();
SourceContextId fetchSourceContextId(SourceId sourceId) const;
Cache::SourceNames fetchAllSourceNames() const;
Cache::Sources fetchAllSources() const;
SourceId fetchSourceIdUnguarded(SourceContextId sourceContextId,
Utils::SmallStringView sourceName);
SourceNameId fetchSourceNameIdUnguarded(Utils::SmallStringView sourceName);
FileStatuses fetchAllFileStatuses() const;
@@ -1009,9 +1006,9 @@ private:
SourceContextId writeSourceContextId(Utils::SmallStringView sourceContextPath);
SourceId writeSourceId(SourceContextId sourceContextId, Utils::SmallStringView sourceName);
SourceNameId writeSourceNameId(Utils::SmallStringView sourceName);
SourceId readSourceId(SourceContextId sourceContextId, Utils::SmallStringView sourceName);
SourceNameId readSourceNameId(Utils::SmallStringView sourceName);
Storage::Synchronization::ExportedTypes fetchExportedTypes(TypeId typeId);

View File

@@ -8,7 +8,7 @@
namespace QmlDesigner {
void ProjectStorageErrorNotifier::typeNameCannotBeResolved(Utils::SmallStringView typeName,
SourceId sourceId)
SourceId sourceId)
{
qDebug() << "Missing type name: " << typeName
<< " in file: " << m_pathCache.sourcePath(sourceId).toStringView();

View File

@@ -47,12 +47,12 @@ const char *SourceContextIdDoesNotExists::what() const noexcept
return "The source context id does not exist in the database!";
}
SourceIdDoesNotExists::SourceIdDoesNotExists()
SourceNameIdDoesNotExists::SourceNameIdDoesNotExists()
{
category().threadEvent("SourceIdDoesNotExists"_t);
category().threadEvent("SourceNameIdDoesNotExists"_t);
}
const char *SourceIdDoesNotExists::what() const noexcept
const char *SourceNameIdDoesNotExists::what() const noexcept
{
return "The source id does not exist in the database!";
}

View File

@@ -55,10 +55,10 @@ public:
const char *what() const noexcept override;
};
class QMLDESIGNERCORE_EXPORT SourceIdDoesNotExists : public ProjectStorageError
class QMLDESIGNERCORE_EXPORT SourceNameIdDoesNotExists : public ProjectStorageError
{
public:
SourceIdDoesNotExists();
SourceNameIdDoesNotExists();
const char *what() const noexcept override;
};

View File

@@ -127,13 +127,16 @@ public:
ids.push_back(id);
outputIterator = std::transform(
idPath.sourceIds.begin(), idPath.sourceIds.end(), outputIterator, [&](SourceId sourceId) {
return WatcherEntry{id,
m_pathCache.sourceContextId(sourceId),
sourceId,
m_fileStatusCache.lastModifiedTime(sourceId)};
});
outputIterator = std::transform(idPath.sourceIds.begin(),
idPath.sourceIds.end(),
outputIterator,
[&](SourceId sourceId) {
return WatcherEntry{id,
sourceId.contextId(),
sourceId,
m_fileStatusCache.lastModifiedTime(
sourceId)};
});
}
std::sort(entries.begin(), entries.end());

View File

@@ -483,7 +483,7 @@ void ProjectStorageUpdater::updateSubdirectories(const Utils::PathString &direct
auto subdirectorySourceIds = m_projectStorage.fetchSubdirectorySourceIds(directorySourceId);
auto subdirectories = Utils::transform<Directories>(
subdirectorySourceIds, [&](SourceId sourceId) -> Directory {
auto sourceContextId = m_pathCache.sourceContextId(sourceId);
auto sourceContextId = sourceId.contextId();
auto subdirectoryPath = m_pathCache.sourceContextPath(sourceContextId);
return {subdirectoryPath, sourceContextId, sourceId};
});
@@ -495,10 +495,9 @@ void ProjectStorageUpdater::updateSubdirectories(const Utils::PathString &direct
|| subdirectory.endsWith("/QtQuick/Scene3D"))
continue;
Utils::PathString subdirectoryPath = subdirectory;
auto [sourceContextId, sourceId] = m_pathCache.sourceContextAndSourceId(
SourcePath{subdirectoryPath + "/."});
subdirectories.emplace_back(subdirectoryPath, sourceContextId, sourceId);
existingSubdirecories.emplace_back(subdirectoryPath, sourceContextId, sourceId);
SourceId sourceId = m_pathCache.sourceId(SourcePath{subdirectoryPath + "/."});
subdirectories.emplace_back(subdirectoryPath, sourceId.contextId(), sourceId);
existingSubdirecories.emplace_back(subdirectoryPath, sourceId.contextId(), sourceId);
}
std::sort(subdirectories.begin(), subdirectories.end());
@@ -828,12 +827,10 @@ void ProjectStorageUpdater::updatePropertyEditorFilePath(
}
namespace {
SourceContextIds filterUniqueSourceContextIds(const SourceIds &sourceIds,
ProjectStorageUpdater::PathCache &pathCache)
SourceContextIds filterUniqueSourceContextIds(const SourceIds &sourceIds)
{
auto sourceContextIds = Utils::transform(sourceIds, [&](SourceId sourceId) {
return pathCache.sourceContextId(sourceId);
});
auto sourceContextIds = Utils::transform(sourceIds,
[](SourceId sourceId) { return sourceId.contextId(); });
std::sort(sourceContextIds.begin(), sourceContextIds.end());
auto newEnd = std::unique(sourceContextIds.begin(), sourceContextIds.end());
@@ -899,7 +896,7 @@ void ProjectStorageUpdater::pathsWithIdsChanged(const std::vector<IdPaths> &chan
}
}
auto directorySourceContextIds = filterUniqueSourceContextIds(directorySourceIds, m_pathCache);
auto directorySourceContextIds = filterUniqueSourceContextIds(directorySourceIds);
for (auto sourceContextId : directorySourceContextIds) {
Utils::PathString directory = m_pathCache.sourceContextPath(sourceContextId);
@@ -911,13 +908,13 @@ void ProjectStorageUpdater::pathsWithIdsChanged(const std::vector<IdPaths> &chan
}
for (SourceId sourceId : filterUniqueSourceIds(qmlDocumentSourceIds)) {
if (!contains(directorySourceContextIds, m_pathCache.sourceContextId(sourceId)))
if (!contains(directorySourceContextIds, sourceId.contextId()))
parseQmlComponent(sourceId, package, notUpdatedSourceIds);
}
try {
for (SourceId sourceId : filterUniqueSourceIds(std::move(qmltypesSourceIds))) {
if (!contains(directorySourceContextIds, m_pathCache.sourceContextId(sourceId))) {
if (!contains(directorySourceContextIds, sourceId.contextId())) {
auto qmltypesPath = m_pathCache.sourcePath(sourceId);
auto directoryInfo = m_projectStorage.fetchDirectoryInfo(sourceId);
if (directoryInfo)

View File

@@ -32,7 +32,7 @@ class SourcePathCache final : public SourcePathCacheInterface
public:
SourcePathCache(ProjectStorage &projectStorage)
: m_sourceContextStorageAdapter{projectStorage}
, m_sourceStorageAdapter{projectStorage}
, m_sourceNameStorageAdapter{projectStorage}
{
populateIfEmpty();
@@ -58,9 +58,9 @@ public:
Utils::SmallStringView sourceName = sourcePath.name();
auto sourceId = m_sourcePathCache.id({sourceName, sourceContextId});
auto sourceId = m_sourcePathCache.id(sourceName);
return {sourceContextId, sourceId};
return {sourceContextId, SourceId::create(sourceId, sourceContextId)};
}
SourceId sourceId(SourcePathView sourcePath) const override
@@ -71,7 +71,9 @@ public:
SourceId sourceId(SourceContextId sourceContextId,
Utils::SmallStringView sourceName) const override
{
return m_sourcePathCache.id({sourceName, sourceContextId});
SourceNameId sourceNameId = m_sourcePathCache.id(sourceName);
return SourceId::create(sourceNameId, sourceContextId);
}
SourceContextId sourceContextId(Utils::SmallStringView sourceContextPath) const override
@@ -88,11 +90,11 @@ public:
if (Q_UNLIKELY(!sourceId.isValid()))
throw NoSourcePathForInvalidSourceId();
auto entry = m_sourcePathCache.value(sourceId);
auto sourceName = m_sourcePathCache.value(sourceId.mainId());
Utils::PathString sourceContextPath = m_sourceContextPathCache.value(entry.sourceContextId);
Utils::PathString sourceContextPath = m_sourceContextPathCache.value(sourceId.contextId());
return SourcePath{sourceContextPath, entry.sourceName};
return SourcePath{sourceContextPath, sourceName};
}
Utils::PathString sourceContextPath(SourceContextId sourceContextId) const override
@@ -103,19 +105,11 @@ public:
return m_sourceContextPathCache.value(sourceContextId);
}
SourceContextId sourceContextId(SourceId sourceId) const override
{
if (Q_UNLIKELY(!sourceId.isValid()))
throw NoSourcePathForInvalidSourceId();
return m_sourcePathCache.value(sourceId).sourceContextId;
}
private:
class SourceContextStorageAdapter
{
public:
auto fetchId(const Utils::SmallStringView sourceContextPath)
auto fetchId(Utils::SmallStringView sourceContextPath)
{
return storage.fetchSourceContextId(sourceContextPath);
}
@@ -127,27 +121,22 @@ private:
ProjectStorage &storage;
};
class SourceStorageAdapter
class SourceNameStorageAdapter
{
public:
auto fetchId(Cache::SourceNameView sourceNameView)
auto fetchId(Utils::SmallStringView sourceNameView)
{
return storage.fetchSourceId(sourceNameView.sourceContextId, sourceNameView.sourceName);
return storage.fetchSourceNameId(sourceNameView);
}
auto fetchValue(SourceId id)
{
auto entry = storage.fetchSourceNameAndSourceContextId(id);
auto fetchValue(SourceNameId id) { return storage.fetchSourceName(id); }
return Cache::SourceNameEntry{std::move(entry.sourceName), entry.sourceContextId};
}
auto fetchAll() { return storage.fetchAllSources(); }
auto fetchAll() { return storage.fetchAllSourceNames(); }
ProjectStorage &storage;
};
static bool sourceContextLess(Utils::SmallStringView first, Utils::SmallStringView second) noexcept
static bool sourceLess(Utils::SmallStringView first, Utils::SmallStringView second) noexcept
{
return std::lexicographical_compare(first.rbegin(),
first.rend(),
@@ -155,31 +144,26 @@ private:
second.rend());
}
static bool sourceLess(Cache::SourceNameView first, Cache::SourceNameView second) noexcept
{
return first < second;
}
using SourceContextPathCache = StorageCache<Utils::PathString,
Utils::SmallStringView,
SourceContextId,
SourceContextStorageAdapter,
Mutex,
sourceContextLess,
sourceLess,
Cache::SourceContext>;
using SourceNameCache = StorageCache<Cache::SourceNameEntry,
Cache::SourceNameView,
SourceId,
SourceStorageAdapter,
using SourceNameCache = StorageCache<Utils::PathString,
Utils::SmallStringView,
SourceNameId,
SourceNameStorageAdapter,
Mutex,
sourceLess,
Cache::Source>;
Cache::SourceName>;
private:
SourceContextStorageAdapter m_sourceContextStorageAdapter;
SourceStorageAdapter m_sourceStorageAdapter;
SourceNameStorageAdapter m_sourceNameStorageAdapter;
mutable SourceContextPathCache m_sourceContextPathCache{m_sourceContextStorageAdapter};
mutable SourceNameCache m_sourcePathCache{m_sourceStorageAdapter};
mutable SourceNameCache m_sourcePathCache{m_sourceNameStorageAdapter};
};
} // namespace QmlDesigner

View File

@@ -36,7 +36,6 @@ public:
virtual SourcePath sourcePath(SourceId sourceId) const = 0;
virtual Utils::PathString sourceContextPath(SourceContextId sourceContextId) const = 0;
virtual SourceContextId sourceContextId(SourceId sourceId) const = 0;
protected:
~SourcePathCacheInterface() = default;

View File

@@ -12,70 +12,6 @@
namespace QmlDesigner::Cache {
class SourceNameView
{
public:
friend bool operator==(const SourceNameView &first, const SourceNameView &second) noexcept
{
return first.sourceContextId == second.sourceContextId
&& first.sourceName == second.sourceName;
}
friend bool operator<(SourceNameView first, SourceNameView second) noexcept
{
return std::tie(first.sourceContextId, first.sourceName)
< std::tie(second.sourceContextId, second.sourceName);
}
public:
Utils::SmallStringView sourceName;
SourceContextId sourceContextId;
};
class SourceNameEntry
{
public:
SourceNameEntry() = default;
SourceNameEntry(Utils::SmallStringView sourceName, SourceContextId sourceContextId)
: sourceName(sourceName)
, sourceContextId(sourceContextId)
{}
SourceNameEntry(SourceNameView view)
: sourceName(view.sourceName)
, sourceContextId(view.sourceContextId)
{}
friend bool operator==(const SourceNameEntry &first, const SourceNameEntry &second) noexcept
{
return first.sourceContextId == second.sourceContextId
&& first.sourceName == second.sourceName;
}
friend bool operator!=(const SourceNameEntry &first, const SourceNameEntry &second) noexcept
{
return !(first == second);
}
friend bool operator==(const SourceNameEntry &first, const SourceNameView &second) noexcept
{
return first.sourceContextId == second.sourceContextId
&& first.sourceName == second.sourceName;
}
friend bool operator!=(const SourceNameEntry &first, const SourceNameView &second) noexcept
{
return !(first == second);
}
operator SourceNameView() const noexcept { return {sourceName, sourceContextId}; }
operator Utils::SmallString() &&noexcept { return std::move(sourceName); }
public:
Utils::SmallString sourceName;
SourceContextId sourceContextId;
};
class SourceContext
: public StorageCacheEntry<Utils::PathString, Utils::SmallStringView, SourceContextId>
@@ -93,38 +29,19 @@ public:
using SourceContexts = std::vector<SourceContext>;
class Source : public StorageCacheEntry<SourceNameEntry, SourceNameView, SourceId>
class SourceName : public StorageCacheEntry<Utils::PathString, Utils::SmallStringView, SourceNameId>
{
using Base = StorageCacheEntry<SourceNameEntry, SourceNameView, SourceId>;
using Base = StorageCacheEntry<Utils::PathString, Utils::SmallStringView, SourceNameId>;
public:
using Base::Base;
Source(Utils::SmallStringView sourceName, SourceContextId sourceContextId, SourceId sourceId)
: Base{{sourceName, sourceContextId}, sourceId}
{}
friend bool operator==(const Source &first, const Source &second)
friend bool operator==(const SourceName &first, const SourceName &second)
{
return first.id == second.id && first.value == second.value;
}
};
using Sources = std::vector<Source>;
class SourceNameAndSourceContextId
{
public:
constexpr SourceNameAndSourceContextId() = default;
SourceNameAndSourceContextId(Utils::SmallStringView sourceName, SourceContextId sourceContextId)
: sourceName{sourceName}
, sourceContextId{sourceContextId}
{}
Utils::SmallString sourceName;
SourceContextId sourceContextId;
};
using SourceNameAndSourceContextIds = std::vector<SourceNameAndSourceContextId>;
using SourceNames = std::vector<SourceName>;
} // namespace QmlDesigner::Cache