QNetworkCookie: add QBAV overload for parseCookies

Rewrite impl to reduce allocations by QL1S::tokenize

Change-Id: I8d131ef6d7fe9a1a9daa438efea026392deb5e55
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Anton Kudryavtsev 2023-08-23 17:50:28 +03:00
parent 5442ebe5e8
commit 98e7da8e32
2 changed files with 12 additions and 3 deletions

View File

@ -930,13 +930,21 @@ static QDateTime parseDateString(QByteArrayView dateString)
\sa toRawForm()
*/
QList<QNetworkCookie> QNetworkCookie::parseCookies(const QByteArray &cookieString)
{
return parseCookies(QByteArrayView(cookieString));
}
/*!
\overload
\since 6.7
*/
QList<QNetworkCookie> QNetworkCookie::parseCookies(QByteArrayView cookieString)
{
// cookieString can be a number of set-cookie header strings joined together
// by \n, parse each line separately.
QList<QNetworkCookie> cookies;
QList<QByteArray> list = cookieString.split('\n');
for (int a = 0; a < list.size(); a++)
cookies += QNetworkCookiePrivate::parseSetCookieHeaderLine(list.at(a));
for (auto s : QLatin1StringView(cookieString).tokenize('\n'_L1))
cookies += QNetworkCookiePrivate::parseSetCookieHeaderLine(s);
return cookies;
}

View File

@ -76,6 +76,7 @@ public:
void normalize(const QUrl &url);
static QList<QNetworkCookie> parseCookies(const QByteArray &cookieString);
static QList<QNetworkCookie> parseCookies(QByteArrayView cookieString);
private:
QSharedDataPointer<QNetworkCookiePrivate> d;