aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-10-01 16:40:59 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2020-01-15 16:46:19 +0100
commite79a2658cde899d6ee11ec3c0d0a3768eb2c864b (patch)
tree79e7d1205cb44236f0ad082ff0c2e75e78046159
parent4527d87e8f24e99658020900d9eb114d86d4dc82 (diff)
Use QFlatMap in QQuickTableView
QFlatMap is implemented to use two containers internally, one for keys and one for values. This improves locality of reference for the purpose of doing binary search to find a key quickly, and also makes the keys() (and values()) accessor really fast. Change-Id: I87bbb06371aeb44c5bcf971d72ae9cd59920f800 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r--src/quick/items/qquicktableview.cpp10
-rw-r--r--src/quick/items/qquicktableview_p_p.h17
2 files changed, 14 insertions, 13 deletions
diff --git a/src/quick/items/qquicktableview.cpp b/src/quick/items/qquicktableview.cpp
index 2e7e07f705..fd511bc2ee 100644
--- a/src/quick/items/qquicktableview.cpp
+++ b/src/quick/items/qquicktableview.cpp
@@ -520,10 +520,10 @@ int QQuickTableViewPrivate::nextVisibleEdgeIndexAroundLoadedTable(Qt::Edge edge)
// visible, and should be loaded next if the content item moves.
int startIndex = -1;
switch (edge) {
- case Qt::LeftEdge: startIndex = loadedColumns.firstKey() - 1; break;
- case Qt::RightEdge: startIndex = loadedColumns.lastKey() + 1; break;
- case Qt::TopEdge: startIndex = loadedRows.firstKey() - 1; break;
- case Qt::BottomEdge: startIndex = loadedRows.lastKey() + 1; break;
+ case Qt::LeftEdge: startIndex = leftColumn() - 1; break;
+ case Qt::RightEdge: startIndex = rightColumn() + 1; break;
+ case Qt::TopEdge: startIndex = topRow() - 1; break;
+ case Qt::BottomEdge: startIndex = bottomRow() + 1; break;
}
return nextVisibleEdgeIndex(edge, startIndex);
@@ -1913,7 +1913,7 @@ void QQuickTableViewPrivate::loadEdge(Qt::Edge edge, QQmlIncubator::IncubationMo
const int edgeIndex = nextVisibleEdgeIndexAroundLoadedTable(edge);
qCDebug(lcTableViewDelegateLifecycle) << edge << edgeIndex;
- const QList<int> visibleCells = edge & (Qt::LeftEdge | Qt::RightEdge)
+ const auto visibleCells = edge & (Qt::LeftEdge | Qt::RightEdge)
? loadedRows.keys() : loadedColumns.keys();
loadRequest.begin(edge, edgeIndex, visibleCells, incubationMode);
processLoadRequest();
diff --git a/src/quick/items/qquicktableview_p_p.h b/src/quick/items/qquicktableview_p_p.h
index ec043f5e7e..7c81882d44 100644
--- a/src/quick/items/qquicktableview_p_p.h
+++ b/src/quick/items/qquicktableview_p_p.h
@@ -54,6 +54,7 @@
#include "qquicktableview_p.h"
#include <QtCore/qtimer.h>
+#include <QtCore/private/qflatmap_p.h>
#include <QtQmlModels/private/qqmltableinstancemodel_p.h>
#include <QtQml/private/qqmlincubator_p.h>
#include <QtQmlModels/private/qqmlchangeset_p.h>
@@ -119,7 +120,7 @@ public:
qCDebug(lcTableViewDelegateLifecycle()) << "begin top-left:" << toString();
}
- void begin(Qt::Edge edgeToLoad, int edgeIndex, const QList<int> visibleCellsInEdge, QQmlIncubator::IncubationMode incubationMode)
+ void begin(Qt::Edge edgeToLoad, int edgeIndex, const QVector<int> visibleCellsInEdge, QQmlIncubator::IncubationMode incubationMode)
{
Q_ASSERT(!m_active);
m_active = true;
@@ -169,7 +170,7 @@ public:
private:
Qt::Edge m_edge = Qt::Edge(0);
- QList<int> m_visibleCellsInEdge;
+ QVector<int> m_visibleCellsInEdge;
int m_edgeIndex = 0;
int m_currentIndex = 0;
bool m_active = false;
@@ -246,8 +247,8 @@ public:
// we need to fill up with more rows/columns. loadedTableInnerRect describes the pixels
// that the loaded table covers if you remove one row/column on each side of the table, and
// is used to determine rows/columns that are no longer visible and can be unloaded.
- QMap<int, int> loadedColumns;
- QMap<int, int> loadedRows;
+ QFlatMap<int, int> loadedColumns;
+ QFlatMap<int, int> loadedRows;
QRectF loadedTableOuterRect;
QRectF loadedTableInnerRect;
@@ -333,10 +334,10 @@ public:
qreal getColumnWidth(int column);
qreal getRowHeight(int row);
- inline int topRow() const { return loadedRows.firstKey(); }
- inline int bottomRow() const { return loadedRows.lastKey(); }
- inline int leftColumn() const { return loadedColumns.firstKey(); }
- inline int rightColumn() const { return loadedColumns.lastKey(); }
+ inline int topRow() const { return loadedRows.cbegin().key(); }
+ inline int bottomRow() const { return (--loadedRows.cend()).key(); }
+ inline int leftColumn() const { return loadedColumns.cbegin().key(); }
+ inline int rightColumn() const { return (--loadedColumns.cend()).key(); }
QQuickTableView *rootSyncView() const;