From 05b2377d2f20b451e8328b1c5a1adf13ec01ebf3 Mon Sep 17 00:00:00 2001 From: Arttu Tarkiainen Date: Mon, 10 Oct 2022 13:43:25 +0300 Subject: Optimize keeping component reference count in InstallerCalculator To avoid constructing possibly large temporary QStringList objects, return the value by modifiable reference when accessing the m_referenceCount container. Task-number: QTIFW-2790 Change-Id: Ieb2619624cfbf12561dbec25b966bb7dbae5d29c Reviewed-by: Katja Marttila --- src/libs/installer/installercalculator.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src/libs') diff --git a/src/libs/installer/installercalculator.cpp b/src/libs/installer/installercalculator.cpp index f71a35858..48c90621b 100644 --- a/src/libs/installer/installercalculator.cpp +++ b/src/libs/installer/installercalculator.cpp @@ -229,13 +229,11 @@ bool InstallerCalculator::appendComponentToInstall(Component *component, const Q if (m_toInstallComponentIds.contains(dependencyComponentName) && m_referenceCount.contains(dependencyComponentName)) { if (!component->autoDependencies().contains(dependencyComponentName)) { - QStringList value = m_referenceCount.value(dependencyComponentName); + QStringList &value = m_referenceCount[dependencyComponentName]; if (value.contains(component->name())) { value.removeOne(component->name()); if (value.isEmpty()) m_referenceCount.remove(dependencyComponentName); - else - m_referenceCount.insert(dependencyComponentName, value); } } } @@ -262,11 +260,8 @@ bool InstallerCalculator::appendComponentToInstall(Component *component, const Q } m_visitedComponents[component].insert(dependencyComponent); } - if (!component->autoDependencies().contains(dependencyComponentName)) { - QStringList value = m_referenceCount.value(dependencyComponentName, QStringList()); - value << component->name(); - m_referenceCount.insert(dependencyComponentName, value); - } + if (!component->autoDependencies().contains(dependencyComponentName)) + m_referenceCount[dependencyComponentName] << component->name(); insertInstallReason(dependencyComponent, InstallerCalculator::Dependent, component->name()); if (!appendComponentToInstall(dependencyComponent, requiredDependencyVersion, revertFromInstall)) -- cgit v1.2.3