From 931f9c23ee884fe929aed50404a29776826d8bd4 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 16 Aug 2014 20:28:10 +0200 Subject: [PATCH] QMacStyle: replace a QSet with QVector Holding a mutable item in a QSet violates QSet invariants, namely that in bucket N, all items have hash % size == N. If a value gets reset to nullptr by external means, that invariant no longer holds. The code works by pure luck. Replace the set with a vector, which doesn't care whether elements change under the hood, and will also outperform the typical QSet use due to better locality of reference. Change-Id: Ied7940e82525fd0da9f74dfb0bc36a320b45d172 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/styles/qmacstyle_mac.mm | 11 +++-------- src/widgets/styles/qmacstyle_mac_p_p.h | 4 ++-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/widgets/styles/qmacstyle_mac.mm b/src/widgets/styles/qmacstyle_mac.mm index 50c8fd7ed8..cf10fe7acd 100644 --- a/src/widgets/styles/qmacstyle_mac.mm +++ b/src/widgets/styles/qmacstyle_mac.mm @@ -114,7 +114,7 @@ QT_NAMESPACE_ALIAS_OBJC_CLASS(NotificationReceiver); { Q_UNUSED(notification); QEvent event(QEvent::StyleChange); - QMutableSetIterator > it(QMacStylePrivate::scrollBars); + QMutableVectorIterator > it(QMacStylePrivate::scrollBars); while (it.hasNext()) { if (!it.next()) it.remove(); @@ -138,12 +138,7 @@ const int QMacStylePrivate::BevelButtonW = 50; const int QMacStylePrivate::BevelButtonH = 22; const int QMacStylePrivate::PushButtonContentPadding = 6; -QSet > QMacStylePrivate::scrollBars; - -static uint qHash(const QPointer &ptr) -{ - return qHash(ptr.data()); -} +QVector > QMacStylePrivate::scrollBars; // Title bar gradient colors for Lion were determined by inspecting PSDs exported // using CoreUI's CoreThemeDocument; there is no public API to retrieve them @@ -5367,7 +5362,7 @@ void QMacStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex // there is not enough space for them. if (cc == CC_ScrollBar) { if (opt && opt->styleObject && !QMacStylePrivate::scrollBars.contains(opt->styleObject)) - QMacStylePrivate::scrollBars.insert(QPointer(opt->styleObject)); + QMacStylePrivate::scrollBars.append(QPointer(opt->styleObject)); const int scrollBarLength = (slider->orientation == Qt::Horizontal) ? slider->rect.width() : slider->rect.height(); const QMacStyle::WidgetSizePolicy sizePolicy = widgetSizePolicy(widget, opt); diff --git a/src/widgets/styles/qmacstyle_mac_p_p.h b/src/widgets/styles/qmacstyle_mac_p_p.h index b09e81d595..33818568ec 100644 --- a/src/widgets/styles/qmacstyle_mac_p_p.h +++ b/src/widgets/styles/qmacstyle_mac_p_p.h @@ -86,7 +86,7 @@ #include #include #include -#include +#include #include #include @@ -213,7 +213,7 @@ public: mutable QPointer pressedButton; mutable QPointer defaultButton; mutable QPointer autoDefaultButton; - static QSet > scrollBars; + static QVector > scrollBars; struct ButtonState { int frame;