From ea76ab2b2ded0197ddf9e33e8d6a8af909fce31c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 6 Oct 2013 22:50:12 +0200 Subject: QtWidgets: replace uses of inefficient QLists with QVectors These QPairs are larger than a void*, so holding them in QLists is needlessly inefficient. Worse, the code could come to depend on the fragile property of (inefficient) QLists that references to elements therein never are invalidated. Fix by holding them in QVector instead. Change-Id: I3c205f5326cfd96482563078bdca1747d718457f Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/dialogs/qsidebar_p.h | 3 ++- src/widgets/graphicsview/qgraph_p.h | 4 ++-- src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp | 6 +++--- src/widgets/itemviews/qtreeview.cpp | 10 +++++----- src/widgets/itemviews/qtreeview_p.h | 3 ++- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/widgets/dialogs/qsidebar_p.h b/src/widgets/dialogs/qsidebar_p.h index f3e20986f0..210c86be01 100644 --- a/src/widgets/dialogs/qsidebar_p.h +++ b/src/widgets/dialogs/qsidebar_p.h @@ -55,6 +55,7 @@ #include #include #include +#include #ifndef QT_NO_FILEDIALOG @@ -106,7 +107,7 @@ private: void changed(const QString &path); void addIndexToWatch(const QString &path, const QModelIndex &index); QFileSystemModel *fileSystemModel; - QList > watching; + QVector > watching; QList invalidUrls; }; diff --git a/src/widgets/graphicsview/qgraph_p.h b/src/widgets/graphicsview/qgraph_p.h index 34c6a8c3c5..14f7122d5c 100644 --- a/src/widgets/graphicsview/qgraph_p.h +++ b/src/widgets/graphicsview/qgraph_p.h @@ -211,8 +211,8 @@ public: return setOfVertices; } - QList > connections() const { - QList > conns; + QVector > connections() const { + QVector > conns; for (const_iterator it = constBegin(); it != constEnd(); ++it) { Vertex *from = it.from(); Vertex *to = it.to(); diff --git a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp index b5865ec9c9..1e5aea9688 100644 --- a/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/widgets/graphicsview/qgraphicsanchorlayout_p.cpp @@ -1266,7 +1266,7 @@ void QGraphicsAnchorLayoutPrivate::restoreSimplifiedGraph(Orientation orientatio // Restore anchor simplification Graph &g = graph[orientation]; - QList > connections = g.connections(); + QVector > connections = g.connections(); for (int i = 0; i < connections.count(); ++i) { AnchorVertex *v1 = connections.at(i).first; AnchorVertex *v2 = connections.at(i).second; @@ -2295,7 +2295,7 @@ bool QGraphicsAnchorLayoutPrivate::calculateNonTrunk(const QList &g = graph[orientation]; - QList > vertices = g.connections(); + QVector > vertices = g.connections(); QLayoutStyleInfo styleInf = styleInfo(); for (int i = 0; i < vertices.count(); ++i) { @@ -2388,7 +2388,7 @@ void QGraphicsAnchorLayoutPrivate::constraintsFromPaths(Orientation orientation) void QGraphicsAnchorLayoutPrivate::updateAnchorSizes(Orientation orientation) { Graph &g = graph[orientation]; - const QList > &vertices = g.connections(); + const QVector > &vertices = g.connections(); for (int i = 0; i < vertices.count(); ++i) { AnchorData *ad = g.edgeData(vertices.at(i).first, vertices.at(i).second); diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index e7d8fc9783..fdd2be69eb 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -3777,8 +3777,8 @@ QRect QTreeViewPrivate::itemDecorationRect(const QModelIndex &index) const return q->style()->subElementRect(QStyle::SE_TreeViewDisclosureItem, &opt, q); } -QList > QTreeViewPrivate::columnRanges(const QModelIndex &topIndex, - const QModelIndex &bottomIndex) const +QVector > QTreeViewPrivate::columnRanges(const QModelIndex &topIndex, + const QModelIndex &bottomIndex) const { const int topVisual = header->visualIndex(topIndex.column()), bottomVisual = header->visualIndex(bottomIndex.column()); @@ -3798,7 +3798,7 @@ QList > QTreeViewPrivate::columnRanges(const QModelIndex &topInd //let's sort the list std::sort(logicalIndexes.begin(), logicalIndexes.end()); - QList > ret; + QVector > ret; QPair current; current.first = -2; // -1 is not enough because -1+1 = 0 current.second = -2; @@ -3832,8 +3832,8 @@ void QTreeViewPrivate::select(const QModelIndex &topIndex, const QModelIndex &bo const int top = viewIndex(topIndex), bottom = viewIndex(bottomIndex); - const QList< QPair > colRanges = columnRanges(topIndex, bottomIndex); - QList< QPair >::const_iterator it; + const QVector > colRanges = columnRanges(topIndex, bottomIndex); + QVector >::const_iterator it; for (it = colRanges.begin(); it != colRanges.end(); ++it) { const int left = (*it).first, right = (*it).second; diff --git a/src/widgets/itemviews/qtreeview_p.h b/src/widgets/itemviews/qtreeview_p.h index 9d2f496c5d..a3619ce13b 100644 --- a/src/widgets/itemviews/qtreeview_p.h +++ b/src/widgets/itemviews/qtreeview_p.h @@ -54,6 +54,7 @@ #include "private/qabstractitemview_p.h" #include #include +#include #ifndef QT_NO_TREEVIEW @@ -164,7 +165,7 @@ public: QRect itemDecorationRect(const QModelIndex &index) const; - QList > columnRanges(const QModelIndex &topIndex, const QModelIndex &bottomIndex) const; + QVector > columnRanges(const QModelIndex &topIndex, const QModelIndex &bottomIndex) const; void select(const QModelIndex &start, const QModelIndex &stop, QItemSelectionModel::SelectionFlags command); QPair startAndEndColumns(const QRect &rect) const; -- cgit v1.2.3