From 9af53bfc8115eab4a6f46e5b38527ed3b669f3f0 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 30 Dec 2014 11:51:30 -0200 Subject: [PATCH] Use a signal for updating the dispatch status The cost of connecting a signal may be a bit high, but it's comparable to looking up the invokable method. However, QMetaMethod::invoke has a higher cost than a signal-slot emission -- though in any case they're both dwarfed by the cost of allocating the QMetaCallEvent and the posting of it. This is much more readable, though. Change-Id: Iccecbecbe6288fb3b6d16578fdff3f203b6db29c Reviewed-by: Alex Blasche Reviewed-by: Albert Astals Cid --- src/dbus/qdbusconnection_p.h | 1 + src/dbus/qdbusintegrator.cpp | 14 +++----------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/dbus/qdbusconnection_p.h b/src/dbus/qdbusconnection_p.h index 9e948bd684..fde7edaa64 100644 --- a/src/dbus/qdbusconnection_p.h +++ b/src/dbus/qdbusconnection_p.h @@ -271,6 +271,7 @@ private slots: void unregisterServiceNoLock(const QString &serviceName); signals: + void dispatchStatusChanged(); void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); void callWithCallbackFailed(const QDBusError &error, const QDBusMessage &message); void newServerConnection(QDBusConnectionPrivate *newConnection); diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 04d2c93ffe..84d433f2e7 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -357,18 +357,8 @@ static void qDBusUpdateDispatchStatus(DBusConnection *connection, DBusDispatchSt Q_ASSERT(connection); Q_UNUSED(connection); QDBusConnectionPrivate *d = static_cast(data); - - static int slotId; // 0 is QObject::deleteLater() - if (!slotId) { - // it's ok to do this: there's no race condition because the store is atomic - // and we always set to the same value - slotId = QDBusConnectionPrivate::staticMetaObject.indexOfSlot("doDispatch()"); - } - - //qDBusDebug() << "Updating dispatcher status" << slotId; if (new_status == DBUS_DISPATCH_DATA_REMAINS) - QDBusConnectionPrivate::staticMetaObject.method(slotId). - invoke(d, Qt::QueuedConnection); + emit d->dispatchStatusChanged(); } static void qDBusNewConnection(DBusServer *server, DBusConnection *connection, void *data) @@ -1030,6 +1020,8 @@ QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p) #endif QDBusMetaTypeId::init(); + connect(this, &QDBusConnectionPrivate::dispatchStatusChanged, + this, &QDBusConnectionPrivate::doDispatch, Qt::QueuedConnection); rootNode.flags = 0;