diff options
author | Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> | 2010-04-07 14:55:01 (GMT) |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dietrich-de@nokia.com> | 2010-04-07 16:05:41 (GMT) |
commit | e1e728daad07600fca7bc1811c92fb05065884c6 (patch) | |
tree | 1a631019ebfa25180b8f86c6dd7646a26a5f5878 /src/gui | |
parent | 99c17c0efb1331f5d11260b08614c9dff9bbf2e1 (diff) | |
download | Qt-e1e728daad07600fca7bc1811c92fb05065884c6.zip Qt-e1e728daad07600fca7bc1811c92fb05065884c6.tar.gz Qt-e1e728daad07600fca7bc1811c92fb05065884c6.tar.bz2 |
O(n^2) to O(n) optimization in QTreeWidget::selectedItems()
As we need to ensure that there will be no duplicates in the list
returned by QTreeWidget::selectedItems() (see commit
ea75d434e40100a9abf56195b646a8efdf3c1288), we now use a QSet to ensure
unicity while keeping the same order as before.
Reviewed-by: Olivier
Task-number: QTBUG-9485
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/itemviews/qtreewidget.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/gui/itemviews/qtreewidget.cpp b/src/gui/itemviews/qtreewidget.cpp index 19ed10b..4c80325 100644 --- a/src/gui/itemviews/qtreewidget.cpp +++ b/src/gui/itemviews/qtreewidget.cpp @@ -3039,10 +3039,14 @@ QList<QTreeWidgetItem*> QTreeWidget::selectedItems() const Q_D(const QTreeWidget); QModelIndexList indexes = selectionModel()->selectedIndexes(); QList<QTreeWidgetItem*> items; + items.reserve(indexes.count()); + QSet<QTreeWidgetItem *> seen; + seen.reserve(indexes.count()); for (int i = 0; i < indexes.count(); ++i) { QTreeWidgetItem *item = d->item(indexes.at(i)); - if (isItemHidden(item) || items.contains(item)) // ### slow, optimize later + if (isItemHidden(item) || seen.contains(item)) continue; + seen.insert(item); items.append(item); } return items; |