File garbage-collect-deleted-objects.patch of Package libqt4

From: David Faure <faure@kde.org>
Date: Tue, 15 Jan 2013 17:41:27 +0000
Subject: QtDBus: Garbage collect deleted objects now and then.
X-Git-Url: http://quickgit.kde.org/?p=qt.git&a=commitdiff&h=cf5442551196c3e7e06e6de85c5f8a198b0ff001
---
QtDBus: Garbage collect deleted objects now and then.

Fixes performance issues in apps which register and deregister objects
very frequently (like nepomukstorage).

Change-Id: Id7d6ef508336758c55fa894868241f143b3e30e0
Backport-Of: ac9ab9703ff299c94dca7585d5a12ecde28931bb
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
---


--- a/src/dbus/qdbusintegrator.cpp
+++ b/src/dbus/qdbusintegrator.cpp
@@ -2216,6 +2216,19 @@
     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*)),
@@ -2239,6 +2252,10 @@
                 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,

openSUSE Build Service is sponsored by