From cea46aa3620bb16f8c03a13d900f5ce066aae21c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 18 Dec 2017 10:42:27 +0100 Subject: [PATCH] QGestureManager: don't abuse a QMap for a set The filterEvents() implementations used a QMap for tracking whether a given type was already seen. The mapped_type was completely unused. Since the expected number of gesture types is very low, go directly to QVarLengthArray, not QSet, as the reduced number of allocation will dwarf the low overhead of O(N) search vs. O(1) for QSet or O(logN) for QMap. Change-Id: I98b6af69f11cca753e3c7c4fbb58e8f2e935e0d5 Reviewed-by: Giuseppe D'Angelo --- src/widgets/kernel/qgesturemanager.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/widgets/kernel/qgesturemanager.cpp b/src/widgets/kernel/qgesturemanager.cpp index 390602205c..7632521117 100644 --- a/src/widgets/kernel/qgesturemanager.cpp +++ b/src/widgets/kernel/qgesturemanager.cpp @@ -509,14 +509,14 @@ void QGestureManager::cleanupGesturesForRemovedRecognizer(QGesture *gesture) // return true if accepted (consumed) bool QGestureManager::filterEvent(QWidget *receiver, QEvent *event) { - QMap types; + QVarLengthArray types; QMultiMap contexts; QWidget *w = receiver; typedef QMap::const_iterator ContextIterator; if (!w->d_func()->gestureContext.isEmpty()) { for(ContextIterator it = w->d_func()->gestureContext.constBegin(), e = w->d_func()->gestureContext.constEnd(); it != e; ++it) { - types.insert(it.key(), 0); + types.push_back(it.key()); contexts.insert(w, it.key()); } } @@ -528,7 +528,7 @@ bool QGestureManager::filterEvent(QWidget *receiver, QEvent *event) e = w->d_func()->gestureContext.constEnd(); it != e; ++it) { if (!(it.value() & Qt::DontStartGestureOnChildren)) { if (!types.contains(it.key())) { - types.insert(it.key(), 0); + types.push_back(it.key()); contexts.insert(w, it.key()); } } @@ -543,14 +543,14 @@ bool QGestureManager::filterEvent(QWidget *receiver, QEvent *event) #if QT_CONFIG(graphicsview) bool QGestureManager::filterEvent(QGraphicsObject *receiver, QEvent *event) { - QMap types; + QVarLengthArray types; QMultiMap contexts; QGraphicsObject *item = receiver; if (!item->QGraphicsItem::d_func()->gestureContext.isEmpty()) { typedef QMap::const_iterator ContextIterator; for(ContextIterator it = item->QGraphicsItem::d_func()->gestureContext.constBegin(), e = item->QGraphicsItem::d_func()->gestureContext.constEnd(); it != e; ++it) { - types.insert(it.key(), 0); + types.push_back(it.key()); contexts.insert(item, it.key()); } } @@ -563,7 +563,7 @@ bool QGestureManager::filterEvent(QGraphicsObject *receiver, QEvent *event) e = item->QGraphicsItem::d_func()->gestureContext.constEnd(); it != e; ++it) { if (!(it.value() & Qt::DontStartGestureOnChildren)) { if (!types.contains(it.key())) { - types.insert(it.key(), 0); + types.push_back(it.key()); contexts.insert(item, it.key()); } }