From 5d44d171274aef3d9e93cac8e958494220234151 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 3 Dec 2015 13:47:27 +0100 Subject: 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) --- src/widgets/styles/qmacstyle_mac.mm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index c20639d20e..7b270d9241 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -118,14 +118,13 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(NotificationReceiver); - (void)scrollBarStyleDidChange:(NSNotification *)notification { Q_UNUSED(notification); + + // purge destroyed scroll bars: + QMacStylePrivate::scrollBars.removeAll(QPointer()); + QEvent event(QEvent::StyleChange); - QMutableVectorIterator > it(QMacStylePrivate::scrollBars); - while (it.hasNext()) { - if (!it.next()) - it.remove(); - else - QCoreApplication::sendEvent(it.value(), &event); - } + for (const auto &o : QMacStylePrivate::scrollBars) + QCoreApplication::sendEvent(o, &event); } @end -- cgit v1.2.3