From 99d9a683b12dbff594e24849e981df78619e0ff1 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 27 Jun 2015 16:40:45 +0200 Subject: [PATCH] QGraphicsItemAnimationPrivate: replace a sort with a rotate There's really no need to sort the whole collection if you a) know it's already sorted and b) already know its final position, because you looked it up using lower_bound a line up. Instead of appending and sorting the whole thing, simply append and rotate into place, conveniently packaged as positional insert. Also reverse the check for presence: less negations: more readable. Change-Id: Id23f108b64976061f666f517fbc436d3c72dd25b Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/graphicsview/qgraphicsitemanimation.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/widgets/graphicsview/qgraphicsitemanimation.cpp b/src/widgets/graphicsview/qgraphicsitemanimation.cpp index f983da015c..585539de94 100644 --- a/src/widgets/graphicsview/qgraphicsitemanimation.cpp +++ b/src/widgets/graphicsview/qgraphicsitemanimation.cpp @@ -176,12 +176,10 @@ void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QV const Pair pair = { step, value }; const QVector::iterator result = std::lower_bound(binList->begin(), binList->end(), pair); - if ((result != binList->end()) && !(pair < *result)) + if (result == binList->end() || pair < *result) + binList->insert(result, pair); + else result->value = value; - else { - *binList << pair; - std::sort(binList->begin(), binList->end()); - } } /*!