summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qgesturemanager.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2017-12-18 10:42:27 +0100
committerMarc Mutz <marc.mutz@kdab.com>2019-05-21 09:15:15 +0200
commitcea46aa3620bb16f8c03a13d900f5ce066aae21c (patch)
tree449f3cbc307350a28f4decec95e76307472a8787 /src/widgets/kernel/qgesturemanager.cpp
parentf7ae47ad07a24e8e26e5afcd0a9b747f25bb7129 (diff)
QGestureManager: don't abuse a QMap for a set
The filterEvents() implementations used a QMap<GestureType, int> 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 <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'src/widgets/kernel/qgesturemanager.cpp')
-rw-r--r--src/widgets/kernel/qgesturemanager.cpp12
1 files 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<Qt::GestureType, int> types;
+ QVarLengthArray<Qt::GestureType, 16> types;
QMultiMap<QObject *, Qt::GestureType> contexts;
QWidget *w = receiver;
typedef QMap<Qt::GestureType, Qt::GestureFlags>::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<Qt::GestureType, int> types;
+ QVarLengthArray<Qt::GestureType, 16> types;
QMultiMap<QObject *, Qt::GestureType> contexts;
QGraphicsObject *item = receiver;
if (!item->QGraphicsItem::d_func()->gestureContext.isEmpty()) {
typedef QMap<Qt::GestureType, Qt::GestureFlags>::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());
}
}