diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2019-05-13 15:10:36 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2019-07-24 18:06:30 +0200 |
commit | c13bb2a66aa2eda89cbb437ea7c7a8c2c0fe8cc6 (patch) | |
tree | 94d6b0b0746dbd82c4b0a4a51a6cb28d1c67655e /src/corelib | |
parent | fd42589b14041d620c51fd7d23877c2749767fb3 (diff) |
QObject: replace QScopedPointer with std::unique_ptr in the implementation
Use the standard tool instead of self-made stuff that cannot decide whether
it wants to be a scoped pointer (why take()?) or a movable one (why no move
special member functions?).
Take advantage of C++11 local structs for pulling the custom deleter into
the scope where its only user is located, too.
Change-Id: I7e097a59edef9adc8455504ae94b8df0f8b9e5d2
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/kernel/qobject.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp index 5c1ae8aa43..d364ae1087 100644 --- a/src/corelib/kernel/qobject.cpp +++ b/src/corelib/kernel/qobject.cpp @@ -93,12 +93,6 @@ QAbstractDynamicMetaObject::~QAbstractDynamicMetaObject() { } - -struct QSlotObjectBaseDeleter { // for use with QScopedPointer<QSlotObjectBase,...> - static void cleanup(QtPrivate::QSlotObjectBase *slot) { - if (slot) slot->destroyIfLastRef(); - } -}; static int *queuedConnectionTypes(const QList<QByteArray> &typeNames) { int *types = new int [typeNames.count() + 1]; @@ -3380,7 +3374,7 @@ QObjectPrivate::Connection *QMetaObjectPrivate::connect(const QObject *sender, type &= Qt::UniqueConnection - 1; } - QScopedPointer<QObjectPrivate::Connection> c(new QObjectPrivate::Connection); + std::unique_ptr<QObjectPrivate::Connection> c{new QObjectPrivate::Connection}; c->sender = s; c->signal_index = signal_index; c->receiver.storeRelaxed(r); @@ -3394,14 +3388,14 @@ QObjectPrivate::Connection *QMetaObjectPrivate::connect(const QObject *sender, c->argumentTypes.storeRelaxed(types); c->callFunction = callFunction; - QObjectPrivate::get(s)->addConnection(signal_index, c.data()); + QObjectPrivate::get(s)->addConnection(signal_index, c.get()); locker.unlock(); QMetaMethod smethod = QMetaObjectPrivate::signal(smeta, signal_index); if (smethod.isValid()) s->connectNotify(smethod); - return c.take(); + return c.release(); } /*! @@ -3791,10 +3785,16 @@ void doActivate(QObject *sender, int signal_index, void **argv) if (c->isSlotObject) { c->slotObj->ref(); - QScopedPointer<QtPrivate::QSlotObjectBase, QSlotObjectBaseDeleter> obj(c->slotObj); + + struct Deleter { + void operator()(QtPrivate::QSlotObjectBase *slot) const { + if (slot) slot->destroyIfLastRef(); + } + }; + const std::unique_ptr<QtPrivate::QSlotObjectBase, Deleter> obj{c->slotObj}; { - Q_TRACE_SCOPE(QMetaObject_activate_slot_functor, obj.data()); + Q_TRACE_SCOPE(QMetaObject_activate_slot_functor, obj.get()); obj->call(receiver, argv); } } else if (c->callFunction && c->method_offset <= receiver->metaObject()->methodOffset()) { @@ -4947,7 +4947,7 @@ QMetaObject::Connection QObjectPrivate::connectImpl(const QObject *sender, int s type = static_cast<Qt::ConnectionType>(type ^ Qt::UniqueConnection); } - QScopedPointer<QObjectPrivate::Connection> c(new QObjectPrivate::Connection); + std::unique_ptr<QObjectPrivate::Connection> c{new QObjectPrivate::Connection}; c->sender = s; c->signal_index = signal_index; QThreadData *td = r->d_func()->threadData; @@ -4962,8 +4962,8 @@ QMetaObject::Connection QObjectPrivate::connectImpl(const QObject *sender, int s c->ownArgumentTypes = false; } - QObjectPrivate::get(s)->addConnection(signal_index, c.data()); - QMetaObject::Connection ret(c.take()); + QObjectPrivate::get(s)->addConnection(signal_index, c.get()); + QMetaObject::Connection ret(c.release()); locker.unlock(); QMetaMethod method = QMetaObjectPrivate::signal(senderMetaObject, signal_index); |