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>
This commit is contained in:
Marc Mutz 2015-12-23 13:26:32 +01:00
parent 4501e25a51
commit 050b682412

View File

@ -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;