QMacStyle: fix quadratic behavior

Repeatedly calling QVector::erase(it) (via QMutableVectorIterator::remove())
results in quadratic runtime.

Separate the removal of expired objects from the sending of the event to
the remaining objects, so we can use QVector::removeAll() for the former,
which does exactly what the old code tried to do, except in linear time.

Use range-for for the sending-loop. This could cause detaches, but since
we modify the container two lines before, and we don't copy it anymore,
anywhere, detaches are impossible.

Change-Id: I9aa6427e3646c8ad92b673fe42a86a0dfe79ee80
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2015-12-03 13:47:27 +01:00
parent dd9df8d31f
commit 5d44d17127

View File

@ -118,14 +118,13 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(NotificationReceiver);
- (void)scrollBarStyleDidChange:(NSNotification *)notification - (void)scrollBarStyleDidChange:(NSNotification *)notification
{ {
Q_UNUSED(notification); Q_UNUSED(notification);
// purge destroyed scroll bars:
QMacStylePrivate::scrollBars.removeAll(QPointer<QObject>());
QEvent event(QEvent::StyleChange); QEvent event(QEvent::StyleChange);
QMutableVectorIterator<QPointer<QObject> > it(QMacStylePrivate::scrollBars); for (const auto &o : QMacStylePrivate::scrollBars)
while (it.hasNext()) { QCoreApplication::sendEvent(o, &event);
if (!it.next())
it.remove();
else
QCoreApplication::sendEvent(it.value(), &event);
}
} }
@end @end