QAbstractItemView: use erase and std::remove_if with QList

... instead of using erase() in a loop, with quadratic complexity.

Change-Id: Id9c70a0d1d27b5057e5bf64c315bd66cbcd67330
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
Anton Kudryavtsev 2016-06-27 12:14:52 +03:00
parent a8c98dcb89
commit b9b3bff424

View File

@ -2604,12 +2604,11 @@ QModelIndexList QAbstractItemView::selectedIndexes() const
QModelIndexList indexes;
if (d->selectionModel) {
indexes = d->selectionModel->selectedIndexes();
QList<QModelIndex>::iterator it = indexes.begin();
while (it != indexes.end())
if (isIndexHidden(*it))
it = indexes.erase(it);
else
++it;
auto isHidden = [this](const QModelIndex &idx) {
return isIndexHidden(idx);
};
const auto end = indexes.end();
indexes.erase(std::remove_if(indexes.begin(), end, isHidden), end);
}
return indexes;
}