Optimize QListViewPrivate::draggablePaintPairs()

Instead of converting a QVector to a QList to a QSet just to
be able to look up some indexes, take the original QVector,
sort it, and use std::binary_search().

Change-Id: If56e9371972b9aaebb033a8a499be306163266e2
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2016-01-05 14:07:37 +01:00
parent e7174533e7
commit 4511075fb4

View File

@ -650,9 +650,10 @@ QItemViewPaintPairs QListViewPrivate::draggablePaintPairs(const QModelIndexList
QRect &rect = *r;
const QRect viewportRect = viewport->rect();
QItemViewPaintPairs ret;
const QSet<QModelIndex> visibleIndexes = intersectingSet(viewportRect.translated(q->horizontalOffset(), q->verticalOffset())).toList().toSet();
QVector<QModelIndex> visibleIndexes = intersectingSet(viewportRect.translated(q->horizontalOffset(), q->verticalOffset()));
std::sort(visibleIndexes.begin(), visibleIndexes.end());
for (const auto &index : indexes) {
if (visibleIndexes.contains(index)) {
if (std::binary_search(visibleIndexes.cbegin(), visibleIndexes.cend(), index)) {
const QRect current = q->visualRect(index);
QItemViewPaintPair p = { current, index };
ret += p;