summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-12-03 13:47:27 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-12-03 19:58:45 +0000
commit5d44d171274aef3d9e93cac8e958494220234151 (patch)
tree76ece45caa3babfa3856798cccc3ae3fb14ed6a5 /src/widgets/styles
parentdd9df8d31f2c484c3fea56b78f959ed912807ff1 (diff)
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>
Diffstat (limited to 'src/widgets/styles')
-rw-r--r--src/widgets/styles/qmacstyle_mac.mm13
1 files changed, 6 insertions, 7 deletions
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<QObject>());
+
QEvent event(QEvent::StyleChange);
- QMutableVectorIterator<QPointer<QObject> > 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