From 6313a1adf5b04cb06b9630110f2be9cada6aeb44 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 10 Mar 2022 14:23:55 +0100 Subject: [PATCH] Extract Method QObjectPrivate::ensureExtraData() ... to centralize the creation of QObjectPrivate::extraData. Change-Id: I04e97779ceb0168fa7660e77e0dab2ed3e1ad03e Reviewed-by: Qt CI Bot Reviewed-by: Giuseppe D'Angelo --- src/corelib/kernel/qobject.cpp | 15 +++++---------- src/corelib/kernel/qobject_p.h | 6 ++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 5275fc4bf7..61023530b5 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -1272,8 +1272,7 @@ void QObject::setObjectName(const QString &name) { Q_D(QObject); - if (!d->extraData) - d->extraData = new QObjectPrivate::ExtraData(d); + d->ensureExtraData(); d->extraData->objectName.removeBindingUnlessInWrapper(); @@ -1287,8 +1286,7 @@ QBindable QObject::bindableObjectName() { Q_D(QObject); - if (!d->extraData) - d->extraData = new QObjectPrivate::ExtraData(d); + d->ensureExtraData(); return QBindable(&d->extraData->objectName); } @@ -1817,8 +1815,7 @@ int QObject::startTimer(int interval, Qt::TimerType timerType) return 0; } int timerId = thisThreadData->eventDispatcher.loadRelaxed()->registerTimer(interval, timerType, this); - if (!d->extraData) - d->extraData = new QObjectPrivate::ExtraData(d); + d->ensureExtraData(); d->extraData->runningTimers.append(timerId); return timerId; } @@ -2278,8 +2275,7 @@ void QObject::installEventFilter(QObject *obj) return; } - if (!d->extraData) - d->extraData = new QObjectPrivate::ExtraData(d); + d->ensureExtraData(); // clean up unused items in the list d->extraData->eventFilters.removeAll((QObject *)nullptr); @@ -4101,8 +4097,7 @@ bool QObject::setProperty(const char *name, const QVariant &value) int id = meta->indexOfProperty(name); if (id < 0) { - if (!d->extraData) - d->extraData = new QObjectPrivate::ExtraData(d); + d->ensureExtraData(); const int idx = d->extraData->propertyNames.indexOf(name); diff --git a/src/corelib/kernel/qobject_p.h b/src/corelib/kernel/qobject_p.h index 1b0706e356..149c6a03a6 100644 --- a/src/corelib/kernel/qobject_p.h +++ b/src/corelib/kernel/qobject_p.h @@ -125,6 +125,12 @@ public: QObjectPrivate *parent; }; + void ensureExtraData() + { + if (!extraData) + extraData = new ExtraData(this); + } + typedef void (*StaticMetaCallFunction)(QObject *, QMetaObject::Call, int, void **); struct Connection; struct SignalVector;