From fb3a62df26331d696e1e97b3703f49199d714d08 Mon Sep 17 00:00:00 2001 From: Arttu Tarkiainen Date: Fri, 30 Sep 2022 15:06:45 +0300 Subject: Optimize retrieving components by name The PackageManagerCore::componentByName(const QString &name) -function is called repeatedly by the InstallerCalculator class and at minimum once for each install script, because we automatically inject a snippet which stores the return value of the function in the 'component' variable for the script context. Create a hash once per each component model reset to make the lookups faster: * This avoids constructing a flat list of components and all their descendants again and again when calling the function. * The linear lookup from the component list is slow because it calls componentMatches() for each element until the satisfactory component was found or the list ends. * The average time complexity of the key lookup from the QHash is constant even for large hashes. Task-number: QTIFW-2790 Change-Id: I580d28f78ac6681d5bcbfbad970002b49de1a830 Reviewed-by: Katja Marttila --- tests/auto/installer/solver/tst_solver.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/auto/installer/solver/tst_solver.cpp b/tests/auto/installer/solver/tst_solver.cpp index 8b5d1fdcf..bdfc4d3df 100644 --- a/tests/auto/installer/solver/tst_solver.cpp +++ b/tests/auto/installer/solver/tst_solver.cpp @@ -192,8 +192,7 @@ private slots: QFETCH(QList, installReason); QFETCH(AutoDependencyHash, autodependencyHash); - InstallerCalculator calc(core, core->components(PackageManagerCore::ComponentType::AllNoReplacements) - , autodependencyHash); + InstallerCalculator calc(core, autodependencyHash); calc.appendComponentsToInstall(selectedComponents); QList result = calc.orderedComponentsToInstall(); @@ -236,7 +235,7 @@ private slots: QFETCH(QList , selectedComponents); QFETCH(QList , expectedResult); - InstallerCalculator calc(core, core->components(PackageManagerCore::ComponentType::AllNoReplacements), QHash()); + InstallerCalculator calc(core, QHash()); QTest::ignoreMessage(QtWarningMsg, "Cannot find missing dependency \"B->=2.0.0\" for \"A\"."); calc.appendComponentsToInstall(selectedComponents); -- cgit v1.2.3