From 04e4835a94417386352b45743dedc5cfcc9d1100 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 16 Dec 2017 18:23:27 +0100 Subject: QTableView: don't convert QSet to QList just to iterate over it Both in drawAndClipSpans(), as well as callee QSpanCollection::spansInRect(), a QSet is used to ensure uniqueness of elements. In both cases, the QSet is converted to QList, and the list is iterated over. Just iterate over the QSet directly... Change-Id: I8c7d17246a3cf836659026bfeadb987f37e476bb Reviewed-by: Giuseppe D'Angelo Reviewed-by: Lars Knoll --- src/widgets/itemviews/qtableview.cpp | 12 +++++------- src/widgets/itemviews/qtableview_p.h | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index 0e03ff2a97..5a15fe14f3 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -169,7 +169,7 @@ void QSpanCollection::clear() /** \internal * return a list to all the spans that spans over cells in the given rectangle */ -QList QSpanCollection::spansInRect(int x, int y, int w, int h) const +QSet QSpanCollection::spansInRect(int x, int y, int w, int h) const { QSet list; Index::const_iterator it_y = index.lowerBound(-y); @@ -191,7 +191,7 @@ QList QSpanCollection::spansInRect(int x, int y, int w, break; --it_y; } - return list.values(); + return list; } #undef DEBUG_SPAN_UPDATE @@ -863,19 +863,17 @@ void QTableViewPrivate::drawAndClipSpans(const QRegion &area, QPainter *painter, bool alternateBase = false; QRegion region = viewport->rect(); - QList visibleSpans; + QSet visibleSpans; bool sectionMoved = verticalHeader->sectionsMoved() || horizontalHeader->sectionsMoved(); if (!sectionMoved) { visibleSpans = spans.spansInRect(logicalColumn(firstVisualColumn), logicalRow(firstVisualRow), lastVisualColumn - firstVisualColumn + 1, lastVisualRow - firstVisualRow + 1); } else { - QSet set; for(int x = firstVisualColumn; x <= lastVisualColumn; x++) for(int y = firstVisualRow; y <= lastVisualRow; y++) - set.insert(spans.spanAt(x,y)); - set.remove(0); - visibleSpans = set.values(); + visibleSpans.insert(spans.spanAt(x,y)); + visibleSpans.remove(nullptr); } for (QSpanCollection::Span *span : qAsConst(visibleSpans)) { diff --git a/src/widgets/itemviews/qtableview_p.h b/src/widgets/itemviews/qtableview_p.h index f629dfcd09..7578e4b448 100644 --- a/src/widgets/itemviews/qtableview_p.h +++ b/src/widgets/itemviews/qtableview_p.h @@ -104,7 +104,7 @@ public: void updateSpan(Span *span, int old_height); Span *spanAt(int x, int y) const; void clear(); - QList spansInRect(int x, int y, int w, int h) const; + QSet spansInRect(int x, int y, int w, int h) const; void updateInsertedRows(int start, int end); void updateInsertedColumns(int start, int end); -- cgit v1.2.3