From 050b68241220a5b52c93e1f4cca3be5e71856357 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 23 Dec 2015 13:26:32 +0100 Subject: 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 --- src/dbus/qdbusintegrator.cpp | 15 +++++++-------- 1 file 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; -- cgit v1.2.3