summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Kudryavtsev <anton.kudryavtsev@vk.team>2023-10-30 18:51:28 +0300
committerAnton Kudryavtsev <anton.kudryavtsev@vk.team>2023-10-30 22:32:44 +0300
commit0774a9c556c45d96e40e60e7fe4d040ec860cec1 (patch)
tree713ecd062afd30906d752f49645fb11d44d72633
parent08fff11232ca6ca5165ba76bd268881a8a0060a1 (diff)
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>
-rw-r--r--src/network/access/qnetworkcookiejar.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/network/access/qnetworkcookiejar.cpp b/src/network/access/qnetworkcookiejar.cpp
index 270408a4bb..9d5bc64ad5 100644
--- a/src/network/access/qnetworkcookiejar.cpp
+++ b/src/network/access/qnetworkcookiejar.cpp
@@ -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;
}