summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-05-04 16:25:52 +0300
committerAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-05-04 15:09:41 +0000
commit691151a2411da76987f3e9cb2b6e278a3cb93767 (patch)
tree65263f8ecbe10ea18a0517e365f179b31d413f5a
parenta76d7094a4c2e512da4c0be39933dd0e4f47a92f (diff)
QUrlQuery: use erase and std::remove_if with QList
... instead of using erase() in a loop, with quadratic complexity. Change-Id: I277ff2527e0a22b3d754b1d14296b9882f164c23 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
-rw-r--r--src/corelib/io/qurlquery.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/corelib/io/qurlquery.cpp b/src/corelib/io/qurlquery.cpp
index a6351d3a21..231a26c211 100644
--- a/src/corelib/io/qurlquery.cpp
+++ b/src/corelib/io/qurlquery.cpp
@@ -43,6 +43,8 @@
#include <QtCore/qhashfunctions.h>
#include <QtCore/qstringlist.h>
+#include <algorithm>
+
QT_BEGIN_NAMESPACE
/*!
@@ -754,14 +756,12 @@ void QUrlQuery::removeQueryItem(const QString &key)
void QUrlQuery::removeAllQueryItems(const QString &key)
{
if (d.constData()) {
- QString encodedKey = d->recodeFromUser(key);
- Map::iterator it = d->itemList.begin();
- while (it != d->itemList.end()) {
- if (it->first == encodedKey)
- it = d->itemList.erase(it);
- else
- ++it;
- }
+ const QString encodedKey = d->recodeFromUser(key);
+ auto firstEqualsEncodedKey = [&encodedKey](const QPair<QString, QString> &item) {
+ return item.first == encodedKey;
+ };
+ const auto end = d->itemList.end();
+ d->itemList.erase(std::remove_if(d->itemList.begin(), end, firstEqualsEncodedKey), end);
}
}