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>
This commit is contained in:
parent
f7ae47ad07
commit
cea46aa362
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user