From 03dcc5c036e887600a65907f1b192b06b2cc6c9b Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Thu, 24 Dec 2015 17:18:48 +0300 Subject: QXcbConnection: use erase and std::remove_if with QVector ... instead of using erase in a loop, with quadratic complexity. Change-Id: Ia5201e0bedca7abec6d485505f61f3f76a028bd1 Reviewed-by: Marc Mutz --- src/plugins/platforms/xcb/qxcbconnection.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index f16bebb758..7348eaac20 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -1691,15 +1691,14 @@ void QXcbConnection::processXcbEvents() if (accepted) continue; - QVector::iterator it = m_peekFuncs.begin(); - while (it != m_peekFuncs.end()) { + auto isWaitingFor = [=](PeekFunc peekFunc) { // These callbacks return true if the event is what they were // waiting for, remove them from the list in that case. - if ((*it)(this, event)) - it = m_peekFuncs.erase(it); - else - ++it; - } + return peekFunc(this, event); + }; + m_peekFuncs.erase(std::remove_if(m_peekFuncs.begin(), m_peekFuncs.end(), + isWaitingFor), + m_peekFuncs.end()); m_reader->unlock(); handleXcbEvent(event); m_reader->lock(); -- cgit v1.2.3