From 0774a9c556c45d96e40e60e7fe4d040ec860cec1 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Mon, 30 Oct 2023 18:51:28 +0300 Subject: qnetworkcookiejar::deleteCookie: port raw loop to algorithm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use std::find_if with const iterators to avoid unconditional detach Change-Id: Ibc9d05586a1926fefba5c6fd73c5b15ee815cd6d Reviewed-by: MÃ¥rten Nordheim --- src/network/access/qnetworkcookiejar.cpp | 11 +++++------ 1 file 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::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; } -- cgit v1.2.3