From 89034600939bbfe241ba3d6136abf7bb6961db52 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Mon, 15 Feb 2016 11:16:39 +0300 Subject: QtBase: use erase and std::remove_if with QList and QVector ... instead of using removeAt in a loop, with quadratic complexity. Change-Id: I38b49e56b12c396db9fc0f1b75d8fb43c503a7f6 Reviewed-by: Marc Mutz --- src/widgets/itemviews/qabstractitemview.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/widgets/itemviews') diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index 6c38c53a77..9bb4497811 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -68,6 +68,8 @@ # include #endif +#include + QT_BEGIN_NAMESPACE QAbstractItemViewPrivate::QAbstractItemViewPrivate() @@ -4459,10 +4461,12 @@ QModelIndexList QAbstractItemViewPrivate::selectedDraggableIndexes() const { Q_Q(const QAbstractItemView); QModelIndexList indexes = q->selectedIndexes(); - for(int i = indexes.count() - 1 ; i >= 0; --i) { - if (!isIndexDragEnabled(indexes.at(i))) - indexes.removeAt(i); - } + auto isNotDragEnabled = [this](const QModelIndex &index) { + return !isIndexDragEnabled(index); + }; + indexes.erase(std::remove_if(indexes.begin(), indexes.end(), + isNotDragEnabled), + indexes.end()); return indexes; } -- cgit v1.2.3