diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2017-12-16 18:23:27 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-05-13 16:39:28 +0000 |
commit | 04e4835a94417386352b45743dedc5cfcc9d1100 (patch) | |
tree | 0e195299741804317140d8a77a8284c7181d6d09 /src/widgets | |
parent | 0d88721d772fd995a39cc2417a2a0dabee403b7d (diff) |
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 <giuseppe.dangelo@kdab.com>
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/itemviews/qtableview.cpp | 12 | ||||
-rw-r--r-- | src/widgets/itemviews/qtableview_p.h | 2 |
2 files changed, 6 insertions, 8 deletions
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::Span *> QSpanCollection::spansInRect(int x, int y, int w, int h) const +QSet<QSpanCollection::Span *> QSpanCollection::spansInRect(int x, int y, int w, int h) const { QSet<Span *> list; Index::const_iterator it_y = index.lowerBound(-y); @@ -191,7 +191,7 @@ QList<QSpanCollection::Span *> 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<QSpanCollection::Span *> visibleSpans; + QSet<QSpanCollection::Span *> visibleSpans; bool sectionMoved = verticalHeader->sectionsMoved() || horizontalHeader->sectionsMoved(); if (!sectionMoved) { visibleSpans = spans.spansInRect(logicalColumn(firstVisualColumn), logicalRow(firstVisualRow), lastVisualColumn - firstVisualColumn + 1, lastVisualRow - firstVisualRow + 1); } else { - QSet<QSpanCollection::Span *> 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<Span *> spansInRect(int x, int y, int w, int h) const; + QSet<Span *> spansInRect(int x, int y, int w, int h) const; void updateInsertedRows(int start, int end); void updateInsertedColumns(int start, int end); |