QtWidgets: replace uses of inefficient QList<QPair>s 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) <ogoffart@woboq.com>bb10
parent
b30ea41945
commit
ea76ab2b2d
|
|
@ -55,6 +55,7 @@
|
|||
#include <qstandarditemmodel.h>
|
||||
#include <qstyleditemdelegate.h>
|
||||
#include <qurl.h>
|
||||
#include <qvector.h>
|
||||
|
||||
#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<QPair<QModelIndex, QString> > watching;
|
||||
QVector<QPair<QModelIndex, QString> > watching;
|
||||
QList<QUrl> invalidUrls;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -211,8 +211,8 @@ public:
|
|||
return setOfVertices;
|
||||
}
|
||||
|
||||
QList<QPair<Vertex*, Vertex*> > connections() const {
|
||||
QList<QPair<Vertex*, Vertex*> > conns;
|
||||
QVector<QPair<Vertex*, Vertex*> > connections() const {
|
||||
QVector<QPair<Vertex*, Vertex*> > conns;
|
||||
for (const_iterator it = constBegin(); it != constEnd(); ++it) {
|
||||
Vertex *from = it.from();
|
||||
Vertex *to = it.to();
|
||||
|
|
|
|||
|
|
@ -1266,7 +1266,7 @@ void QGraphicsAnchorLayoutPrivate::restoreSimplifiedGraph(Orientation orientatio
|
|||
|
||||
// Restore anchor simplification
|
||||
Graph<AnchorVertex, AnchorData> &g = graph[orientation];
|
||||
QList<QPair<AnchorVertex*, AnchorVertex*> > connections = g.connections();
|
||||
QVector<QPair<AnchorVertex*, AnchorVertex*> > 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<QSimplexConstra
|
|||
void QGraphicsAnchorLayoutPrivate::refreshAllSizeHints(Orientation orientation)
|
||||
{
|
||||
Graph<AnchorVertex, AnchorData> &g = graph[orientation];
|
||||
QList<QPair<AnchorVertex *, AnchorVertex *> > vertices = g.connections();
|
||||
QVector<QPair<AnchorVertex *, AnchorVertex *> > 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<AnchorVertex, AnchorData> &g = graph[orientation];
|
||||
const QList<QPair<AnchorVertex *, AnchorVertex *> > &vertices = g.connections();
|
||||
const QVector<QPair<AnchorVertex *, AnchorVertex *> > &vertices = g.connections();
|
||||
|
||||
for (int i = 0; i < vertices.count(); ++i) {
|
||||
AnchorData *ad = g.edgeData(vertices.at(i).first, vertices.at(i).second);
|
||||
|
|
|
|||
|
|
@ -3777,8 +3777,8 @@ QRect QTreeViewPrivate::itemDecorationRect(const QModelIndex &index) const
|
|||
return q->style()->subElementRect(QStyle::SE_TreeViewDisclosureItem, &opt, q);
|
||||
}
|
||||
|
||||
QList<QPair<int, int> > QTreeViewPrivate::columnRanges(const QModelIndex &topIndex,
|
||||
const QModelIndex &bottomIndex) const
|
||||
QVector<QPair<int, int> > 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<QPair<int, int> > QTreeViewPrivate::columnRanges(const QModelIndex &topInd
|
|||
//let's sort the list
|
||||
std::sort(logicalIndexes.begin(), logicalIndexes.end());
|
||||
|
||||
QList<QPair<int, int> > ret;
|
||||
QVector<QPair<int, int> > ret;
|
||||
QPair<int, int> 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<int, int> > colRanges = columnRanges(topIndex, bottomIndex);
|
||||
QList< QPair<int, int> >::const_iterator it;
|
||||
const QVector<QPair<int, int> > colRanges = columnRanges(topIndex, bottomIndex);
|
||||
QVector<QPair<int, int> >::const_iterator it;
|
||||
for (it = colRanges.begin(); it != colRanges.end(); ++it) {
|
||||
const int left = (*it).first,
|
||||
right = (*it).second;
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@
|
|||
#include "private/qabstractitemview_p.h"
|
||||
#include <QtCore/qvariantanimation.h>
|
||||
#include <QtCore/qabstractitemmodel.h>
|
||||
#include <QtCore/qvector.h>
|
||||
|
||||
#ifndef QT_NO_TREEVIEW
|
||||
|
||||
|
|
@ -164,7 +165,7 @@ public:
|
|||
QRect itemDecorationRect(const QModelIndex &index) const;
|
||||
|
||||
|
||||
QList<QPair<int, int> > columnRanges(const QModelIndex &topIndex, const QModelIndex &bottomIndex) const;
|
||||
QVector<QPair<int, int> > columnRanges(const QModelIndex &topIndex, const QModelIndex &bottomIndex) const;
|
||||
void select(const QModelIndex &start, const QModelIndex &stop, QItemSelectionModel::SelectionFlags command);
|
||||
|
||||
QPair<int,int> startAndEndColumns(const QRect &rect) const;
|
||||
|
|
|
|||
Loading…
Reference in New Issue