From 4ee081c2f70d0f37dfcc71f717bca25c132db4fc Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Fri, 1 Sep 2023 18:07:47 +0300 Subject: [PATCH] qauthenticator: reduce allocations in parseHttpResponse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit by QBAV usage. While touching code, port index based loop to range based Change-Id: I06a784b94678b901d1074cca224c926e8534bd8e Reviewed-by: MÃ¥rten Nordheim --- src/network/kernel/qauthenticator.cpp | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/network/kernel/qauthenticator.cpp b/src/network/kernel/qauthenticator.cpp index 8293218e36..605db065c5 100644 --- a/src/network/kernel/qauthenticator.cpp +++ b/src/network/kernel/qauthenticator.cpp @@ -450,7 +450,8 @@ void QAuthenticatorPrivate::parseHttpResponse(const QList ¤t = values.at(i); + QByteArrayView headerVal; + for (const auto ¤t : values) { if (current.first.compare(search, Qt::CaseInsensitive) != 0) continue; - QByteArray str = current.second.toLower(); - if (method < Basic && str.startsWith("basic")) { + const QLatin1StringView str(current.second); + if (method < Basic && str.startsWith("basic"_L1, Qt::CaseInsensitive)) { method = Basic; - headerVal = current.second.mid(6); - } else if (method < Ntlm && str.startsWith("ntlm")) { + headerVal = QByteArrayView(current.second).mid(6); + } else if (method < Ntlm && str.startsWith("ntlm"_L1, Qt::CaseInsensitive)) { method = Ntlm; - headerVal = current.second.mid(5); - } else if (method < DigestMd5 && str.startsWith("digest")) { + headerVal = QByteArrayView(current.second).mid(5); + } else if (method < DigestMd5 && str.startsWith("digest"_L1, Qt::CaseInsensitive)) { // Make sure the algorithm is actually MD5 before committing to it: if (!verifyDigestMD5(QByteArrayView(current.second).sliced(7))) continue; method = DigestMd5; - headerVal = current.second.mid(7); - } else if (method < Negotiate && str.startsWith("negotiate")) { + headerVal = QByteArrayView(current.second).mid(7); + } else if (method < Negotiate && str.startsWith("negotiate"_L1, Qt::CaseInsensitive)) { #if QT_CONFIG(sspi) || QT_CONFIG(gssapi) // if it's not supported then we shouldn't try to use it #if QT_CONFIG(gssapi) // For GSSAPI there needs to be a KDC set up for the host (afaict). @@ -492,14 +492,14 @@ void QAuthenticatorPrivate::parseHttpResponse(const QList options = parseDigestAuthenticationChallenge(challenge); // Sets phase to Start if this updates our realm and sets the two locations where we store