From 4e5a0cd02b83f0ea2c7b6066ecb3465488b923de Mon Sep 17 00:00:00 2001 From: Marco Bubke Date: Wed, 27 Mar 2024 17:07:10 +0100 Subject: QmlDesigner: Improve performance of prototype walk The optimizer took quite often the slow join first. So now we have one method to walk the prototype chain and then use the type ids in simpler statements to get the end result. Task-number: QTCREATORBUG-30599 Change-Id: I3e9d4ec85ba75801769eb8760fda6e0400300899 Reviewed-by: Thomas Hartmann Reviewed-by: Qt CI Patch Build Bot --- tests/unit/tests/mocks/projectstoragemock.cpp | 22 +++++++------ tests/unit/tests/mocks/projectstoragemock.h | 37 ++++++++++++---------- .../propertyeditorcomponentgenerator-test.cpp | 2 +- tests/unit/tests/unittests/model/model-test.cpp | 16 +++++++--- 4 files changed, 45 insertions(+), 32 deletions(-) (limited to 'tests') diff --git a/tests/unit/tests/mocks/projectstoragemock.cpp b/tests/unit/tests/mocks/projectstoragemock.cpp index 83ff85fe9a3..27e5c152d21 100644 --- a/tests/unit/tests/mocks/projectstoragemock.cpp +++ b/tests/unit/tests/mocks/projectstoragemock.cpp @@ -227,7 +227,9 @@ void ProjectStorageMock::setItemLibraryEntries( } namespace { -void addBaseProperties(TypeId typeId, TypeIds baseTypeIds, ProjectStorageMock &storage) +void addBaseProperties(TypeId typeId, + const QmlDesigner::SmallTypeIds<16> &baseTypeIds, + ProjectStorageMock &storage) { for (TypeId baseTypeId : baseTypeIds) { for (const auto &propertyId : storage.localPropertyDeclarationIds(baseTypeId)) { @@ -254,7 +256,7 @@ TypeId ProjectStorageMock::createType(ModuleId moduleId, PropertyDeclarationTraits defaultPropertyTraits, TypeId defaultPropertyTypeId, Storage::TypeTraits typeTraits, - TypeIds baseTypeIds, + const QmlDesigner::SmallTypeIds<16> &baseTypeIds, SourceId sourceId) { if (auto id = typeId(moduleId, typeName)) { @@ -290,10 +292,9 @@ TypeId ProjectStorageMock::createType(ModuleId moduleId, for (TypeId baseTypeId : baseTypeIds) ON_CALL(*this, isBasedOn(Eq(typeId), Eq(baseTypeId))).WillByDefault(Return(true)); - TypeIds selfAndPrototypes; - selfAndPrototypes.reserve(baseTypeIds.size() + 1); + QmlDesigner::SmallTypeIds<16> selfAndPrototypes; selfAndPrototypes.push_back(typeId); - selfAndPrototypes.insert(selfAndPrototypes.end(), baseTypeIds.begin(), baseTypeIds.end()); + std::copy(baseTypeIds.begin(), baseTypeIds.end(), std::back_inserter(selfAndPrototypes)); ON_CALL(*this, prototypeAndSelfIds(Eq(typeId))).WillByDefault(Return(selfAndPrototypes)); ON_CALL(*this, prototypeIds(Eq(typeId))).WillByDefault(Return(baseTypeIds)); @@ -314,7 +315,7 @@ void ProjectStorageMock::removeType(QmlDesigner::ModuleId moduleId, Utils::Small QmlDesigner::TypeId ProjectStorageMock::createType(QmlDesigner::ModuleId moduleId, Utils::SmallStringView typeName, QmlDesigner::Storage::TypeTraits typeTraits, - QmlDesigner::TypeIds baseTypeIds, + const QmlDesigner::SmallTypeIds<16> &baseTypeIds, SourceId sourceId) { return createType(moduleId, typeName, {}, {}, TypeId{}, typeTraits, baseTypeIds, sourceId); @@ -325,7 +326,7 @@ TypeId ProjectStorageMock::createObject(ModuleId moduleId, Utils::SmallStringView defaultPropertyName, PropertyDeclarationTraits defaultPropertyTraits, QmlDesigner::TypeId defaultPropertyTypeId, - TypeIds baseTypeIds, + const QmlDesigner::SmallTypeIds<16> &baseTypeIds, QmlDesigner::SourceId sourceId) { return createType(moduleId, @@ -340,19 +341,20 @@ TypeId ProjectStorageMock::createObject(ModuleId moduleId, TypeId ProjectStorageMock::createObject(ModuleId moduleId, Utils::SmallStringView typeName, - TypeIds baseTypeIds) + const QmlDesigner::SmallTypeIds<16> &baseTypeIds) { return createType(moduleId, typeName, Storage::TypeTraitsKind::Reference, baseTypeIds); } QmlDesigner::TypeId ProjectStorageMock::createValue(QmlDesigner::ModuleId moduleId, Utils::SmallStringView typeName, - QmlDesigner::TypeIds baseTypeIds) + const QmlDesigner::SmallTypeIds<16> &baseTypeIds) { return createType(moduleId, typeName, Storage::TypeTraitsKind::Value, baseTypeIds); } -void ProjectStorageMock::setHeirs(QmlDesigner::TypeId typeId, QmlDesigner::TypeIds heirIds) +void ProjectStorageMock::setHeirs(QmlDesigner::TypeId typeId, + const QmlDesigner::SmallTypeIds<64> &heirIds) { ON_CALL(*this, heirIds(typeId)).WillByDefault(Return(heirIds)); } diff --git a/tests/unit/tests/mocks/projectstoragemock.h b/tests/unit/tests/mocks/projectstoragemock.h index 198e54b370b..ed370bde96f 100644 --- a/tests/unit/tests/mocks/projectstoragemock.h +++ b/tests/unit/tests/mocks/projectstoragemock.h @@ -56,7 +56,7 @@ public: QmlDesigner::Storage::PropertyDeclarationTraits defaultPropertyTraits, QmlDesigner::TypeId defaultPropertyTypeId, QmlDesigner::Storage::TypeTraits typeTraits, - QmlDesigner::TypeIds baseTypeIds = {}, + const QmlDesigner::SmallTypeIds<16> &baseTypeIds = {}, QmlDesigner::SourceId sourceId = QmlDesigner::SourceId{}); void removeType(QmlDesigner::ModuleId moduleId, Utils::SmallStringView typeName); @@ -64,27 +64,26 @@ public: QmlDesigner::TypeId createType(QmlDesigner::ModuleId moduleId, Utils::SmallStringView typeName, QmlDesigner::Storage::TypeTraits typeTraits, - QmlDesigner::TypeIds baseTypeIds = {}, + const QmlDesigner::SmallTypeIds<16> &baseTypeIds = {}, QmlDesigner::SourceId sourceId = QmlDesigner::SourceId{}); - QmlDesigner::TypeId createObject( - QmlDesigner::ModuleId moduleId, - Utils::SmallStringView typeName, - Utils::SmallStringView defaultPropertyName, - QmlDesigner::Storage::PropertyDeclarationTraits defaultPropertyTraits, - QmlDesigner::TypeId defaultPropertyTypeId, - QmlDesigner::TypeIds baseTypeIds = {}, - QmlDesigner::SourceId sourceId = QmlDesigner::SourceId{}); + QmlDesigner::TypeId createObject(QmlDesigner::ModuleId moduleId, + Utils::SmallStringView typeName, + Utils::SmallStringView defaultPropertyName, + QmlDesigner::Storage::PropertyDeclarationTraits defaultPropertyTraits, + QmlDesigner::TypeId defaultPropertyTypeId, + const QmlDesigner::SmallTypeIds<16> &baseTypeIds = {}, + QmlDesigner::SourceId sourceId = QmlDesigner::SourceId{}); QmlDesigner::TypeId createObject(QmlDesigner::ModuleId moduleId, Utils::SmallStringView typeName, - QmlDesigner::TypeIds baseTypeIds = {}); + const QmlDesigner::SmallTypeIds<16> &baseTypeIds = {}); QmlDesigner::TypeId createValue(QmlDesigner::ModuleId moduleId, Utils::SmallStringView typeName, - QmlDesigner::TypeIds baseTypeIds = {}); + const QmlDesigner::SmallTypeIds<16> &baseTypeIds = {}); - void setHeirs(QmlDesigner::TypeId typeId, QmlDesigner::TypeIds heirIds); + void setHeirs(QmlDesigner::TypeId typeId, const QmlDesigner::SmallTypeIds<64> &heirIds); QmlDesigner::PropertyDeclarationId createProperty( QmlDesigner::TypeId typeId, @@ -215,9 +214,15 @@ public: propertyName, (QmlDesigner::PropertyDeclarationId propertyDeclarationId), (const, override)); - MOCK_METHOD(QmlDesigner::TypeIds, prototypeAndSelfIds, (QmlDesigner::TypeId type), (const, override)); - MOCK_METHOD(QmlDesigner::TypeIds, prototypeIds, (QmlDesigner::TypeId type), (const, override)); - MOCK_METHOD(QmlDesigner::TypeIds, heirIds, (QmlDesigner::TypeId type), (const, override)); + MOCK_METHOD(QmlDesigner::SmallTypeIds<16>, + prototypeAndSelfIds, + (QmlDesigner::TypeId type), + (const, override)); + MOCK_METHOD(QmlDesigner::SmallTypeIds<16>, + prototypeIds, + (QmlDesigner::TypeId type), + (const, override)); + MOCK_METHOD(QmlDesigner::SmallTypeIds<64>, heirIds, (QmlDesigner::TypeId type), (const, override)); MOCK_METHOD(bool, isBasedOn, (QmlDesigner::TypeId typeId, QmlDesigner::TypeId), (const, override)); MOCK_METHOD(bool, isBasedOn, diff --git a/tests/unit/tests/unittests/componentcore/propertyeditorcomponentgenerator-test.cpp b/tests/unit/tests/unittests/componentcore/propertyeditorcomponentgenerator-test.cpp index 3b9a8bbfe25..d2f2143a737 100644 --- a/tests/unit/tests/unittests/componentcore/propertyeditorcomponentgenerator-test.cpp +++ b/tests/unit/tests/unittests/componentcore/propertyeditorcomponentgenerator-test.cpp @@ -18,7 +18,7 @@ class PropertyEditorComponentGenerator : public ::testing::Test { protected: QmlDesigner::NodeMetaInfo createType(Utils::SmallStringView name, - QmlDesigner::TypeIds baseTypeIds = {}) + const QmlDesigner::SmallTypeIds<16> &baseTypeIds = {}) { auto typeId = projectStorageMock.createValue(qtQuickModuleId, name, baseTypeIds); diff --git a/tests/unit/tests/unittests/model/model-test.cpp b/tests/unit/tests/unittests/model/model-test.cpp index bda942fec0b..bd34a3a6b12 100644 --- a/tests/unit/tests/unittests/model/model-test.cpp +++ b/tests/unit/tests/unittests/model/model-test.cpp @@ -116,11 +116,11 @@ protected: NiceMock pathCacheMock{"/path/foo.qml"}; NiceMock projectStorageMock{pathCacheMock.sourceId}; NiceMock resourceManagementMock; + QmlDesigner::Imports imports = {QmlDesigner::Import::createLibraryImport("QtQuick")}; QmlDesigner::Model model{{projectStorageMock, pathCacheMock}, "Item", - -1, - -1, - nullptr, + imports, + pathCacheMock.path.toQString(), std::make_unique( resourceManagementMock)}; NiceMock viewMock; @@ -541,7 +541,10 @@ TEST_F(Model, by_default_remove_properties_removes_property) TEST_F(Model, by_default_remove_model_node_in_factory_method_calls_removes_node) { model.detachView(&viewMock); - auto newModel = QmlDesigner::Model::create({projectStorageMock, pathCacheMock}, "QtQuick.Item"); + auto newModel = QmlDesigner::Model::create({projectStorageMock, pathCacheMock}, + "Item", + imports, + pathCacheMock.path.toQString()); newModel->attachView(&viewMock); auto node = createNodeWithParent(viewMock.rootModelNode()); @@ -553,7 +556,10 @@ TEST_F(Model, by_default_remove_model_node_in_factory_method_calls_removes_node) TEST_F(Model, by_default_remove_properties_in_factory_method_calls_remove_property) { model.detachView(&viewMock); - auto newModel = QmlDesigner::Model::create({projectStorageMock, pathCacheMock}, "QtQuick.Item"); + auto newModel = QmlDesigner::Model::create({projectStorageMock, pathCacheMock}, + "Item", + imports, + pathCacheMock.path.toQString()); newModel->attachView(&viewMock); rootNode = viewMock.rootModelNode(); auto property = createProperty(rootNode, "yi"); -- cgit v1.2.3