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) <ogoffart@woboq.com>
bb10
Marc Mutz 2015-06-27 16:40:45 +02:00
parent 1a1ca59e2d
commit 99d9a683b1
1 changed files with 3 additions and 5 deletions

View File

@ -176,12 +176,10 @@ void QGraphicsItemAnimationPrivate::insertUniquePair(qreal step, qreal value, QV
const Pair pair = { step, value };
const QVector<Pair>::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());
}
}
/*!