diff options
author | Marco Bubke <marco.bubke@qt.io> | 2021-11-30 15:24:28 +0100 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2021-12-08 15:01:23 +0000 |
commit | 4e99b1380497d3182dfb3559b2a2dd6cff73d828 (patch) | |
tree | ed0938e38fa931d14f5893ea9d8831e7d7089a8c | |
parent | 6009f65b9b557fd4c820ef102773b1e9c83f36be (diff) |
QmlDesigner: Make the member of BasicId private
This prevents that it is changed by accident. It should be anyway not
accessed outside of tests and the storage.
The reinterpret cast is defined behavior.
It would be nice to make the constructor private too but it is used widely
in the tests.
Change-Id: Ib0e8393cc950a651138c1e87c1b6a7b3e5a836f2
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
3 files changed, 10 insertions, 9 deletions
diff --git a/src/plugins/qmldesigner/designercore/include/projectstorageids.h b/src/plugins/qmldesigner/designercore/include/projectstorageids.h index 241a052658..082855fd91 100644 --- a/src/plugins/qmldesigner/designercore/include/projectstorageids.h +++ b/src/plugins/qmldesigner/designercore/include/projectstorageids.h @@ -80,6 +80,7 @@ auto toIntegers(const Container &container) { using DataType = typename Container::value_type::DatabaseType; const DataType *data = reinterpret_cast<const DataType *>(container.data()); + return Utils::span{data, container.size()}; } diff --git a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h index 2c56dfdc29..0a0058d1b9 100644 --- a/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h +++ b/src/plugins/qmldesigner/designercore/projectstorage/projectstorage.h @@ -269,7 +269,7 @@ public: SourceContextId fetchSourceContextId(SourceId sourceId) const { auto sourceContextId = selectSourceContextIdFromSourcesBySourceIdStatement - .template valueWithTransaction<SourceContextId>(sourceId.id); + .template valueWithTransaction<SourceContextId>(&sourceId); if (!sourceContextId) throw SourceIdDoesNotExists(); @@ -337,7 +337,7 @@ private: friend bool operator==(const Module &first, const Module &second) { - return first.id == second.id && first.value == second.value; + return &first == &second && first.value == second.value; } }; @@ -541,11 +541,11 @@ private: const SourceIds &updatedProjectSourceIds) { auto compareKey = [](auto &&first, auto &&second) { - auto projectSourceIdDifference = first.projectSourceId.id - second.projectSourceId.id; + auto projectSourceIdDifference = &first.projectSourceId - &second.projectSourceId; if (projectSourceIdDifference != 0) return projectSourceIdDifference; - return first.sourceId.id - second.sourceId.id; + return &first.sourceId - &second.sourceId; }; std::sort(projectDatas.begin(), projectDatas.end(), [&](auto &&first, auto &&second) { @@ -599,7 +599,7 @@ private: }); auto compareKey = [](auto &&first, auto &&second) { - return first.sourceId.id - second.sourceId.id; + return &first.sourceId - &second.sourceId; }; std::sort(fileStatuses.begin(), fileStatuses.end(), [&](auto &&first, auto &&second) { @@ -933,7 +933,7 @@ private: auto compareKey = [](const Storage::ExportedTypeView &view, const Storage::ExportedType &type) -> long long { - auto moduleIdDifference = view.moduleId.id - type.moduleId.id; + auto moduleIdDifference = &view.moduleId - &type.moduleId; if (moduleIdDifference != 0) return moduleIdDifference; @@ -1221,11 +1221,11 @@ private: auto compareKey = [](const Storage::ImportView &view, const Storage::Import &import) -> long long { - auto sourceIdDifference = view.sourceId.id - import.sourceId.id; + auto sourceIdDifference = &view.sourceId - &import.sourceId; if (sourceIdDifference != 0) return sourceIdDifference; - auto moduleIdDifference = view.moduleId.id - import.moduleId.id; + auto moduleIdDifference = &view.moduleId - &import.moduleId; if (moduleIdDifference != 0) return moduleIdDifference; diff --git a/tests/unit/unittest/projectstorage-test.cpp b/tests/unit/unittest/projectstorage-test.cpp index 2bc88619aa..1e2cc0bd06 100644 --- a/tests/unit/unittest/projectstorage-test.cpp +++ b/tests/unit/unittest/projectstorage-test.cpp @@ -95,7 +95,7 @@ MATCHER_P4(IsStorageType, const Storage::Type &type = arg; return type.sourceId == sourceId && type.typeName == typeName - && type.accessSemantics == accessSemantics && prototypeId.id == type.prototypeId.id; + && type.accessSemantics == accessSemantics && &prototypeId == &type.prototypeId; } MATCHER_P(IsExportedType, |