From b095e0a85b1caef592f01f9786c56ac301a42dcf Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Tue, 16 Aug 2016 18:41:48 +0300 Subject: QQuickPathView: de-duplicate calls and cache results Change-Id: I4b49b912c068fd5c76a2c2c8580f616cb42e9bdb Reviewed-by: Shawn Rutledge --- src/quick/items/qquickpathview.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/quick/items/qquickpathview.cpp') diff --git a/src/quick/items/qquickpathview.cpp b/src/quick/items/qquickpathview.cpp index 1533a14831..c061c8159a 100644 --- a/src/quick/items/qquickpathview.cpp +++ b/src/quick/items/qquickpathview.cpp @@ -1543,8 +1543,9 @@ QQuickItem *QQuickPathView::itemAt(qreal x, qreal y) const QPointF QQuickPathViewPrivate::pointNear(const QPointF &point, qreal *nearPercent) const { - qreal samples = qMin(path->path().length()/5, qreal(500.0)); - qreal res = path->path().length()/samples; + const auto pathLength = path->path().length(); + qreal samples = qMin(pathLength / 5, qreal(500.0)); + qreal res = pathLength / samples; qreal mindist = 1e10; // big number QPointF nearPoint = path->pointAt(0); @@ -1741,12 +1742,13 @@ void QQuickPathViewPrivate::handleMouseReleaseEvent(QMouseEvent *) qreal velocity = calcVelocity(); qreal count = pathItems == -1 ? modelCount : qMin(pathItems, modelCount); - qreal pixelVelocity = (path->path().length()/count) * velocity; + const auto averageItemLength = path->path().length() / count; + qreal pixelVelocity = averageItemLength * velocity; if (qAbs(pixelVelocity) > MinimumFlickVelocity) { if (qAbs(pixelVelocity) > maximumFlickVelocity || snapMode == QQuickPathView::SnapOneItem) { // limit velocity qreal maxVel = velocity < 0 ? -maximumFlickVelocity : maximumFlickVelocity; - velocity = maxVel / (path->path().length()/count); + velocity = maxVel / averageItemLength; } // Calculate the distance to be travelled qreal v2 = velocity*velocity; -- cgit v1.2.3