From a03a71e332294aa500ac8475bb777c2f33609e8b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 1 Mar 2012 10:09:02 +0100 Subject: [PATCH] examples: use QVector instead of QList QPointF is in the category of types for which QList is needlessly inefficient (elements are copy-constructed onto the heap and held through pointers). Use a vector instead. This is consistent with the QPainter API. Change-Id: Id0e910c067a60d12fbc175e7ee7da824834be374 Reviewed-by: hjk Reviewed-by: Lars Knoll --- examples/animation/stickman/animation.cpp | 9 +++------ examples/graphicsview/chip/chip.h | 2 +- .../widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp | 2 +- .../gui/graphicsview/qgraphicsview/benchapps/chipTest/chip.h | 2 +- .../benchmarks/gui/graphicsview/qgraphicsview/chiptester/chip.h | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/examples/animation/stickman/animation.cpp b/examples/animation/stickman/animation.cpp index 4469b36..afdfae6 100644 --- a/examples/animation/stickman/animation.cpp +++ b/examples/animation/stickman/animation.cpp @@ -41,6 +41,7 @@ #include "animation.h" #include +#include #include #include @@ -57,11 +58,7 @@ public: void setNodeCount(int nodeCount) { - while (nodeCount > m_nodePositions.size()) - m_nodePositions.append(QPointF()); - - while (nodeCount < m_nodePositions.size()) - m_nodePositions.removeLast(); + m_nodePositions.resize(nodeCount); } QPointF nodePos(int idx) const @@ -75,7 +72,7 @@ public: } private: - QList m_nodePositions; + QVector m_nodePositions; }; Animation::Animation() diff --git a/examples/graphicsview/chip/chip.h b/examples/graphicsview/chip/chip.h index 04fae2d..4c1cfae 100644 --- a/examples/graphicsview/chip/chip.h +++ b/examples/graphicsview/chip/chip.h @@ -62,7 +62,7 @@ protected: private: int x, y; QColor color; - QList stuff; + QVector stuff; }; #endif diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index 220c89e..daa06d0 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -2153,7 +2153,7 @@ void tst_QGraphicsScene::mouseEventPropagation_doubleclick() class Scene : public QGraphicsScene { public: - QList mouseMovePoints; + QVector mouseMovePoints; protected: void mouseMoveEvent(QGraphicsSceneMouseEvent *event) diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/chipTest/chip.h b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/chipTest/chip.h index b13f4a1..d2d859b 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/chipTest/chip.h +++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/chipTest/chip.h @@ -62,7 +62,7 @@ protected: private: int x, y; QColor color; - QList stuff; + QVector stuff; }; #endif diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/chiptester/chip.h b/tests/benchmarks/gui/graphicsview/qgraphicsview/chiptester/chip.h index ef3550e..462109e 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsview/chiptester/chip.h +++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/chiptester/chip.h @@ -62,7 +62,7 @@ protected: private: int x, y; QColor color; - QList stuff; + QVector stuff; }; #endif -- 2.7.4