qnetworkcookiejar::deleteCookie: port raw loop to algorithm

Use std::find_if with const iterators to avoid unconditional detach

Change-Id: Ibc9d05586a1926fefba5c6fd73c5b15ee815cd6d
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Anton Kudryavtsev 2023-10-30 18:51:28 +03:00
parent 08fff11232
commit 0774a9c556

View File

@ -288,12 +288,11 @@ bool QNetworkCookieJar::updateCookie(const QNetworkCookie &cookie)
bool QNetworkCookieJar::deleteCookie(const QNetworkCookie &cookie)
{
Q_D(QNetworkCookieJar);
QList<QNetworkCookie>::Iterator it;
for (it = d->allCookies.begin(); it != d->allCookies.end(); ++it) {
if (it->hasSameIdentifier(cookie)) {
d->allCookies.erase(it);
return true;
}
const auto it = std::find_if(d->allCookies.cbegin(), d->allCookies.cend(),
[&cookie](const auto &c) { return c.hasSameIdentifier(cookie); });
if (it != d->allCookies.cend()) {
d->allCookies.erase(it);
return true;
}
return false;
}