From 26281561fec5bf850d32040dc16f5f8b5f1aa58f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 17 Aug 2014 20:44:39 +0200 Subject: QGraphicsItemAnimation: don't hold Private::Pair in QList QGraphicsItemAnimationPrivate::Pair, being a (qreal,qreal) is larger than a void*, so holding them in a QList 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 marking Pair as primitive and holding it in QVector instead. Change-Id: I190721f4b0cdeab2efab2d51536f64572cd663df Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../graphicsview/qgraphicsitemanimation.cpp | 31 +++++++++++----------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/widgets/graphicsview/qgraphicsitemanimation.cpp b/src/widgets/graphicsview/qgraphicsitemanimation.cpp index e5f0149d64..214a66ac41 100644 --- a/src/widgets/graphicsview/qgraphicsitemanimation.cpp +++ b/src/widgets/graphicsview/qgraphicsitemanimation.cpp @@ -124,21 +124,22 @@ public: qreal step; qreal value; }; - QList xPosition; - QList yPosition; - QList rotation; - QList verticalScale; - QList horizontalScale; - QList verticalShear; - QList horizontalShear; - QList xTranslation; - QList yTranslation; - - qreal linearValueForStep(qreal step, QList *source, qreal defaultValue = 0); - void insertUniquePair(qreal step, qreal value, QList *binList, const char* method); + QVector xPosition; + QVector yPosition; + QVector rotation; + QVector verticalScale; + QVector horizontalScale; + QVector verticalShear; + QVector horizontalShear; + QVector xTranslation; + QVector yTranslation; + + qreal linearValueForStep(qreal step, QVector *source, qreal defaultValue = 0); + void insertUniquePair(qreal step, qreal value, QVector *binList, const char* method); }; +Q_DECLARE_TYPEINFO(QGraphicsItemAnimationPrivate::Pair, Q_PRIMITIVE_TYPE); -qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, QList *source, qreal defaultValue) +qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, QVector *source, qreal defaultValue) { if (source->isEmpty()) return defaultValue; @@ -168,14 +169,14 @@ qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, QList return valueBefore + (valueAfter - valueBefore) * ((step - stepBefore) / (stepAfter - stepBefore)); } -void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QList *binList, const char* method) +void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QVector *binList, const char* method) { if (!check_step_valid(step, method)) return; Pair pair(step, value); - QList::iterator result = std::lower_bound(binList->begin(), binList->end(), pair); + const QVector::iterator result = std::lower_bound(binList->begin(), binList->end(), pair); if ((result != binList->end()) && !(pair < *result)) result->value = value; else { -- cgit v1.2.3