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>
This commit is contained in:
parent
5b6fd71d3a
commit
931f9c23ee
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user