diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2014-08-17 20:44:39 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-06-28 21:10:25 +0000 |
commit | 26281561fec5bf850d32040dc16f5f8b5f1aa58f (patch) | |
tree | 65d23d6128d32507a6cb1ea003096282ab0f3396 /src | |
parent | dff10573f27aa93650030e2634c5eb3632b3cfdd (diff) |
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) <ogoffart@woboq.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/widgets/graphicsview/qgraphicsitemanimation.cpp | 31 |
1 files changed, 16 insertions, 15 deletions
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<Pair> xPosition; - QList<Pair> yPosition; - QList<Pair> rotation; - QList<Pair> verticalScale; - QList<Pair> horizontalScale; - QList<Pair> verticalShear; - QList<Pair> horizontalShear; - QList<Pair> xTranslation; - QList<Pair> yTranslation; - - qreal linearValueForStep(qreal step, QList<Pair> *source, qreal defaultValue = 0); - void insertUniquePair(qreal step, qreal value, QList<Pair> *binList, const char* method); + QVector<Pair> xPosition; + QVector<Pair> yPosition; + QVector<Pair> rotation; + QVector<Pair> verticalScale; + QVector<Pair> horizontalScale; + QVector<Pair> verticalShear; + QVector<Pair> horizontalShear; + QVector<Pair> xTranslation; + QVector<Pair> yTranslation; + + qreal linearValueForStep(qreal step, QVector<Pair> *source, qreal defaultValue = 0); + void insertUniquePair(qreal step, qreal value, QVector<Pair> *binList, const char* method); }; +Q_DECLARE_TYPEINFO(QGraphicsItemAnimationPrivate::Pair, Q_PRIMITIVE_TYPE); -qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, QList<Pair> *source, qreal defaultValue) +qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, QVector<Pair> *source, qreal defaultValue) { if (source->isEmpty()) return defaultValue; @@ -168,14 +169,14 @@ qreal QGraphicsItemAnimationPrivate::linearValueForStep(qreal step, QList<Pair> return valueBefore + (valueAfter - valueBefore) * ((step - stepBefore) / (stepAfter - stepBefore)); } -void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QList<Pair> *binList, const char* method) +void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QVector<Pair> *binList, const char* method) { if (!check_step_valid(step, method)) return; Pair pair(step, value); - QList<Pair>::iterator result = std::lower_bound(binList->begin(), binList->end(), pair); + const QVector<Pair>::iterator result = std::lower_bound(binList->begin(), binList->end(), pair); if ((result != binList->end()) && !(pair < *result)) result->value = value; else { |