summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjkobus <jaroslaw.kobus@theqtcompany.com>2014-11-19 12:25:19 +0100
committerJarek Kobus <jaroslaw.kobus@theqtcompany.com>2014-12-15 15:31:46 +0100
commit03575555a58a5112f48120985a0006b6e3596991 (patch)
treecedbd96b48c8550dc396e2df523f256b359abd5d
parentfb29c6c6ca89129109131d6c1a889cebcf48fc11 (diff)
Optimize the loop gathering the parents of component set
Change-Id: Ia01398de4d92a8973460afb6d916f34694808bb0 Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
-rw-r--r--src/libs/installer/componentmodel.cpp30
1 files changed, 9 insertions, 21 deletions
diff --git a/src/libs/installer/componentmodel.cpp b/src/libs/installer/componentmodel.cpp
index 4c4bda080..9ff43a598 100644
--- a/src/libs/installer/componentmodel.cpp
+++ b/src/libs/installer/componentmodel.cpp
@@ -470,15 +470,6 @@ void ComponentModel::collectComponents(Component *const component, const QModelI
namespace ComponentModelPrivate {
-struct NameGreaterThan
-{
- bool operator() (const Component *lhs, const Component *rhs) const
- {
- return lhs->name() > rhs->name();
- }
-};
-
-// call it only for items with childern
static Qt::CheckState verifyPartiallyChecked(Component *component)
{
bool anyChecked = false;
@@ -514,22 +505,19 @@ static Qt::CheckState verifyPartiallyChecked(Component *component)
QSet<QModelIndex> ComponentModel::updateCheckedState(const ComponentSet &components, Qt::CheckState state)
{
// get all parent nodes for the components we're going to update
- ComponentSet nodes = components;
- foreach (Component *const component, components) {
- if (Component *parent = component->parentComponent()) {
- nodes.insert(parent);
- while (parent->parentComponent() != 0) {
- parent = parent->parentComponent();
- nodes.insert(parent);
- }
+ QMap<QString, Component *> sortedNodesMap;
+ foreach (Component *component, components) {
+ while (component && !sortedNodesMap.values(component->name()).contains(component)) {
+ sortedNodesMap.insertMulti(component->name(), component);
+ component = component->parentComponent();
}
}
QSet<QModelIndex> changed;
- // sort the nodes, so we can start in descending order to check node and tri-state nodes properly
- ComponentList sortedNodes = nodes.toList();
- std::sort(sortedNodes.begin(), sortedNodes.end(), ComponentModelPrivate::NameGreaterThan());
- foreach (Component *const node, sortedNodes) {
+ const ComponentList sortedNodes = sortedNodesMap.values();
+ // we can start in descending order to check node and tri-state nodes properly
+ for (int i = sortedNodes.count(); i > 0; i--) {
+ Component * const node = sortedNodes.at(i - 1);
if (!node->isCheckable())
continue;