QListView: avoid quadratic complexity in selectedIndexes().
Use std::remove_if(), which is linear, instead of looping over erase(it), which turns the loop quadratic. Reorder condition: call cheap non-virtual QModelIndex::column() first, then virtuals parent(), and isIndexHidden(). Change-Id: Id46ee1297b91906332eeca98f69372ef887ac330 Reviewed-by: Marc Mutz <marc.mutz@kdab.com> Reviewed-by: Edward Welbourne <edward.welbourne@theqtcompany.com>
This commit is contained in:
parent
d392826959
commit
ad9340de99
@ -1440,13 +1440,11 @@ QModelIndexList QListView::selectedIndexes() const
|
||||
return QModelIndexList();
|
||||
|
||||
QModelIndexList viewSelected = d->selectionModel->selectedIndexes();
|
||||
for (int i = 0; i < viewSelected.count();) {
|
||||
const QModelIndex &index = viewSelected.at(i);
|
||||
if (!isIndexHidden(index) && index.parent() == d->root && index.column() == d->column)
|
||||
++i;
|
||||
else
|
||||
viewSelected.removeAt(i);
|
||||
}
|
||||
auto ignorable = [this, d](const QModelIndex &index) {
|
||||
return index.column() != d->column || index.parent() != d->root || isIndexHidden(index);
|
||||
};
|
||||
viewSelected.erase(std::remove_if(viewSelected.begin(), viewSelected.end(), ignorable),
|
||||
viewSelected.end());
|
||||
return viewSelected;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user