QGestureManager: clean up cleanupCachedGestures()
- use logarithmic QMap::find() instead of iterate-and-compare-with-key (linear) - don't convert a QList to a QSet just to use QSet -=, just iterate over QSet::remove(): QSet::subtract() doesn't do anything more fancy, either (saves memory allocations) - replace Q_FOREACH with ranged-for, avoid copies Change-Id: I451f034767b079efa9ee19e2c1fe7dc4af2d9bea Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>bb10
parent
2596a8a55c
commit
dea7110b29
|
|
@ -167,30 +167,26 @@ void QGestureManager::unregisterGestureRecognizer(Qt::GestureType type)
|
|||
|
||||
void QGestureManager::cleanupCachedGestures(QObject *target, Qt::GestureType type)
|
||||
{
|
||||
QMap<ObjectGesture, QList<QGesture *> >::Iterator iter = m_objectGestures.begin();
|
||||
while (iter != m_objectGestures.end()) {
|
||||
ObjectGesture objectGesture = iter.key();
|
||||
if (objectGesture.gesture == type && target == objectGesture.object) {
|
||||
QSet<QGesture *> gestures = QSet<QGesture *>(iter.value().constBegin(), iter.value().constEnd());
|
||||
for (QHash<QGestureRecognizer *, QSet<QGesture *> >::iterator
|
||||
it = m_obsoleteGestures.begin(), e = m_obsoleteGestures.end(); it != e; ++it) {
|
||||
it.value() -= gestures;
|
||||
}
|
||||
foreach (QGesture *g, gestures) {
|
||||
m_deletedRecognizers.remove(g);
|
||||
m_gestureToRecognizer.remove(g);
|
||||
m_maybeGestures.remove(g);
|
||||
m_activeGestures.remove(g);
|
||||
m_gestureOwners.remove(g);
|
||||
m_gestureTargets.remove(g);
|
||||
m_gesturesToDelete.insert(g);
|
||||
}
|
||||
const auto iter = m_objectGestures.find({target, type});
|
||||
if (iter == m_objectGestures.end())
|
||||
return;
|
||||
|
||||
iter = m_objectGestures.erase(iter);
|
||||
} else {
|
||||
++iter;
|
||||
}
|
||||
const QList<QGesture *> &gestures = iter.value();
|
||||
for (auto &e : m_obsoleteGestures) {
|
||||
for (QGesture *g : gestures)
|
||||
e -= g;
|
||||
}
|
||||
for (QGesture *g : gestures) {
|
||||
m_deletedRecognizers.remove(g);
|
||||
m_gestureToRecognizer.remove(g);
|
||||
m_maybeGestures.remove(g);
|
||||
m_activeGestures.remove(g);
|
||||
m_gestureOwners.remove(g);
|
||||
m_gestureTargets.remove(g);
|
||||
m_gesturesToDelete.insert(g);
|
||||
}
|
||||
|
||||
m_objectGestures.erase(iter);
|
||||
}
|
||||
|
||||
// get or create a QGesture object that will represent the state for a given object, used by the recognizer
|
||||
|
|
|
|||
Loading…
Reference in New Issue