summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2014-08-16 20:28:10 +0200
committerMarc Mutz <marc.mutz@kdab.com>2015-06-24 13:14:35 +0000
commit931f9c23ee884fe929aed50404a29776826d8bd4 (patch)
treea9141e4e97ce04d00bc701a2570b2db4866978a7
parent5b6fd71d3a640900d5a938db2af053111e962fcf (diff)
QMacStyle: replace a QSet<QPointer> with QVector<QPointer>
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) <ogoffart@woboq.com>
-rw-r--r--src/widgets/styles/qmacstyle_mac.mm11
-rw-r--r--src/widgets/styles/qmacstyle_mac_p_p.h4
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<QPointer<QObject> > it(QMacStylePrivate::scrollBars);
+ QMutableVectorIterator<QPointer<QObject> > 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<QPointer<QObject> > QMacStylePrivate::scrollBars;
-
-static uint qHash(const QPointer<QObject> &ptr)
-{
- return qHash(ptr.data());
-}
+QVector<QPointer<QObject> > 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<QObject>(opt->styleObject));
+ QMacStylePrivate::scrollBars.append(QPointer<QObject>(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 <qdatetimeedit.h>
#include <qmath.h>
#include <qpair.h>
-#include <qset.h>
+#include <qvector.h>
#include <QtWidgets/qgraphicsproxywidget.h>
#include <QtWidgets/qgraphicsview.h>
@@ -213,7 +213,7 @@ public:
mutable QPointer<QObject> pressedButton;
mutable QPointer<QObject> defaultButton;
mutable QPointer<QObject> autoDefaultButton;
- static QSet<QPointer<QObject> > scrollBars;
+ static QVector<QPointer<QObject> > scrollBars;
struct ButtonState {
int frame;