summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-12-23 13:26:32 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-12-27 14:25:40 +0000
commit050b68241220a5b52c93e1f4cca3be5e71856357 (patch)
treeee63b98b23aa09f91231b6d2b7a6ad7b6760da20
parent4501e25a510c0e3b156816f4559ca16e69264306 (diff)
QDBusIntegrator: fix quadratic behavior
Calling QVector::erase(it) in a loop consitutes quadratic behavior (O(N) function called O(N) times). Fix by using std::remove_if(), which is linear. Change-Id: I39c11231d604bc2d9506427bc3411b71d71b5569 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/dbus/qdbusintegrator.cpp15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp
index 1aac16119b..0aa9b27750 100644
--- a/src/dbus/qdbusintegrator.cpp
+++ b/src/dbus/qdbusintegrator.cpp
@@ -517,15 +517,14 @@ bool QDBusConnectionPrivate::handleMessage(const QDBusMessage &amsg)
static void huntAndDestroy(QObject *needle, QDBusConnectionPrivate::ObjectTreeNode &haystack)
{
- QDBusConnectionPrivate::ObjectTreeNode::DataList::Iterator it = haystack.children.begin();
+ for (auto &node : haystack.children)
+ huntAndDestroy(needle, node);
- while (it != haystack.children.end()) {
- huntAndDestroy(needle, *it);
- if (!it->isActive())
- it = haystack.children.erase(it);
- else
- it++;
- }
+ auto isInactive = [](QDBusConnectionPrivate::ObjectTreeNode &node) { return !node.isActive(); };
+
+ haystack.children.erase(std::remove_if(haystack.children.begin(), haystack.children.end(),
+ isInactive),
+ haystack.children.end());
if (needle == haystack.obj) {
haystack.obj = 0;