QScroller: maintain activeScrollers as a QList, not a QSet
The number of active scrollers is probably very low, so O(N) vs. O(1) search can be neglected, compared to the higher cost of allocating and iterating a QSet. The tipping point is that the public API uses QList, and the QSet needs to be converted toList() on each (external) access. Just use a QList. Change-Id: I5f0b37761923dc94d6dbbbf92973da73f5335e4a Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
This commit is contained in:
parent
e31c79ece4
commit
8b8e53f726
@ -281,10 +281,9 @@ private:
|
||||
*/
|
||||
|
||||
typedef QMap<QObject *, QScroller *> ScrollerHash;
|
||||
typedef QSet<QScroller *> ScrollerSet;
|
||||
|
||||
Q_GLOBAL_STATIC(ScrollerHash, qt_allScrollers)
|
||||
Q_GLOBAL_STATIC(ScrollerSet, qt_activeScrollers)
|
||||
Q_GLOBAL_STATIC(QList<QScroller *>, qt_activeScrollers)
|
||||
|
||||
/*!
|
||||
Returns \c true if a QScroller object was already created for \a target; \c false otherwise.
|
||||
@ -335,7 +334,7 @@ const QScroller *QScroller::scroller(const QObject *target)
|
||||
*/
|
||||
QList<QScroller *> QScroller::activeScrollers()
|
||||
{
|
||||
return qt_activeScrollers()->toList();
|
||||
return *qt_activeScrollers();
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -512,7 +511,7 @@ QScroller::~QScroller()
|
||||
d->recognizer = 0;
|
||||
#endif
|
||||
qt_allScrollers()->remove(d->target);
|
||||
qt_activeScrollers()->remove(this);
|
||||
qt_activeScrollers()->removeOne(this);
|
||||
|
||||
delete d_ptr;
|
||||
}
|
||||
@ -1768,9 +1767,9 @@ void QScrollerPrivate::setState(QScroller::State newstate)
|
||||
firstScroll = true;
|
||||
}
|
||||
if (state == QScroller::Dragging || state == QScroller::Scrolling)
|
||||
qt_activeScrollers()->insert(q);
|
||||
qt_activeScrollers()->push_back(q);
|
||||
else
|
||||
qt_activeScrollers()->remove(q);
|
||||
qt_activeScrollers()->removeOne(q);
|
||||
emit q->stateChanged(state);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user