diff options
author | David Faure <faure+bluesystems@kde.org> | 2013-01-14 13:58:05 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-01-17 17:39:36 +0100 |
commit | ac9ab9703ff299c94dca7585d5a12ecde28931bb (patch) | |
tree | 3c061e37f63fc7efac20a4bbd2630dca6f69decb | |
parent | 00e0923e6044323a58af53217547c61a9e6ff2c1 (diff) |
QtDBus: Garbage collect deleted objects now and then.
Fixes performance issues in apps which register and deregister objects
very frequently (like nepomukstorage).
Change-Id: Ib4ce8d65868f0e26cd45f1053e4b2f4c13528cfa
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/dbus/qdbusintegrator.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 2b3ee901a5..42e6a80670 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -2224,6 +2224,19 @@ QDBusConnectionPrivate::disconnectSignal(SignalHookHash::Iterator &it) return signalHooks.erase(it); } + +static void cleanupDeletedNodes(QDBusConnectionPrivate::ObjectTreeNode &parent) +{ + QMutableVectorIterator<QDBusConnectionPrivate::ObjectTreeNode> it(parent.children); + while (it.hasNext()) { + QDBusConnectionPrivate::ObjectTreeNode& node = it.next(); + if (node.obj == 0 && node.children.isEmpty()) + it.remove(); + else + cleanupDeletedNodes(node); + } +} + void QDBusConnectionPrivate::registerObject(const ObjectTreeNode *node) { connect(node->obj, SIGNAL(destroyed(QObject*)), SLOT(objectDestroyed(QObject*)), @@ -2247,6 +2260,10 @@ void QDBusConnectionPrivate::registerObject(const ObjectTreeNode *node) this, SLOT(relaySignal(QObject*,const QMetaObject*,int,QVariantList)), Qt::DirectConnection); } + + static int counter = 0; + if ((++counter % 20) == 0) + cleanupDeletedNodes(rootNode); } void QDBusConnectionPrivate::connectRelay(const QString &service, |