qnetworkrequest: reduce branches in loop

Unconditionally append separator and then chop last one

Change-Id: I33d004df07ce0c3c0076dc374ae7a2f8c413aeba
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Anton Kudryavtsev 2023-08-24 17:28:46 +03:00
parent 5c5c9dd830
commit 6cc1a84005

View File

@ -1096,14 +1096,14 @@ static QByteArray headerValue(QNetworkRequest::KnownHeaders header, const QVaria
if (cookies.isEmpty() && value.userType() == qMetaTypeId<QNetworkCookie>())
cookies << qvariant_cast<QNetworkCookie>(value);
constexpr QByteArrayView separator = "; ";
QByteArray result;
bool first = true;
for (const QNetworkCookie &cookie : std::as_const(cookies)) {
if (!first)
result += "; ";
first = false;
result += cookie.toRawForm(QNetworkCookie::NameAndValueOnly);
result += separator;
}
if (!result.isEmpty())
result.chop(separator.size());
return result;
}
@ -1111,15 +1111,15 @@ static QByteArray headerValue(QNetworkRequest::KnownHeaders header, const QVaria
QList<QNetworkCookie> cookies = qvariant_cast<QList<QNetworkCookie> >(value);
if (cookies.isEmpty() && value.userType() == qMetaTypeId<QNetworkCookie>())
cookies << qvariant_cast<QNetworkCookie>(value);
\
constexpr QByteArrayView separator = ", ";
QByteArray result;
bool first = true;
for (const QNetworkCookie &cookie : std::as_const(cookies)) {
if (!first)
result += ", ";
first = false;
result += cookie.toRawForm(QNetworkCookie::Full);
result += separator;
}
if (!result.isEmpty())
result.chop(separator.size());
return result;
}
}