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>
This commit is contained in:
parent
a76d7094a4
commit
691151a241
@ -43,6 +43,8 @@
|
|||||||
#include <QtCore/qhashfunctions.h>
|
#include <QtCore/qhashfunctions.h>
|
||||||
#include <QtCore/qstringlist.h>
|
#include <QtCore/qstringlist.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -754,14 +756,12 @@ void QUrlQuery::removeQueryItem(const QString &key)
|
|||||||
void QUrlQuery::removeAllQueryItems(const QString &key)
|
void QUrlQuery::removeAllQueryItems(const QString &key)
|
||||||
{
|
{
|
||||||
if (d.constData()) {
|
if (d.constData()) {
|
||||||
QString encodedKey = d->recodeFromUser(key);
|
const QString encodedKey = d->recodeFromUser(key);
|
||||||
Map::iterator it = d->itemList.begin();
|
auto firstEqualsEncodedKey = [&encodedKey](const QPair<QString, QString> &item) {
|
||||||
while (it != d->itemList.end()) {
|
return item.first == encodedKey;
|
||||||
if (it->first == encodedKey)
|
};
|
||||||
it = d->itemList.erase(it);
|
const auto end = d->itemList.end();
|
||||||
else
|
d->itemList.erase(std::remove_if(d->itemList.begin(), end, firstEqualsEncodedKey), end);
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user