diff options
author | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2022-09-30 15:06:45 +0300 |
---|---|---|
committer | Arttu Tarkiainen <arttu.tarkiainen@qt.io> | 2022-10-11 13:55:10 +0000 |
commit | fb3a62df26331d696e1e97b3703f49199d714d08 (patch) | |
tree | 3a2e246c9cf8a0c2d301a4a64eb61dc5f52e359e /src/libs/installer/packagemanagercore_p.cpp | |
parent | 6032600abadded7d2fd4890a7cd07b36ed06e117 (diff) |
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 <name, component> 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 <katja.marttila@qt.io>
Diffstat (limited to 'src/libs/installer/packagemanagercore_p.cpp')
-rw-r--r-- | src/libs/installer/packagemanagercore_p.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/libs/installer/packagemanagercore_p.cpp b/src/libs/installer/packagemanagercore_p.cpp index eddb44555..f4d47b718 100644 --- a/src/libs/installer/packagemanagercore_p.cpp +++ b/src/libs/installer/packagemanagercore_p.cpp @@ -459,6 +459,7 @@ void PackageManagerCorePrivate::cleanUpComponentEnvironment() m_autoDependencyComponentHash.clear(); m_localDependencyComponentHash.clear(); m_localVirtualComponents.clear(); + m_componentByNameHash.clear(); // clean up registered (downloaded) data if (m_core->isMaintainer()) BinaryFormatEngineHandler::instance()->clear(); @@ -564,8 +565,7 @@ InstallerCalculator *PackageManagerCorePrivate::installerCalculator() const { if (!m_installerCalculator) { PackageManagerCorePrivate *const pmcp = const_cast<PackageManagerCorePrivate *> (this); - pmcp->m_installerCalculator = new InstallerCalculator(m_core, - m_core->components(PackageManagerCore::ComponentType::AllNoReplacements), pmcp->m_autoDependencyComponentHash); + pmcp->m_installerCalculator = new InstallerCalculator(m_core, pmcp->m_autoDependencyComponentHash); } return m_installerCalculator; } |