From 68a20d69419671f28990052aca4c89a52ee78046 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sat, 25 Apr 2020 17:58:03 +0200 Subject: QNetworkProxy: don't allocate when parsing [1/2]: loop body MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of manipulating a QByteArray, do it with a QLatin1String, which is free. Also, don't prepend a dot to force matches at label boundaries, check that there's a dot where the match occurred. Saves two allocations per iteration. Finally, pull the query's peerHostName() initialization out of the loop - it doesn't depend on the loop variable. Change-Id: I6dfdae711f0bd8941af69bfbcfda7873a40e4b80 Reviewed-by: MÃ¥rten Nordheim --- src/network/kernel/qnetworkproxy_generic.cpp | 30 ++++++++++++++++------------ 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/network/kernel') diff --git a/src/network/kernel/qnetworkproxy_generic.cpp b/src/network/kernel/qnetworkproxy_generic.cpp index 3ff0cc5168..d2c7b29bc4 100644 --- a/src/network/kernel/qnetworkproxy_generic.cpp +++ b/src/network/kernel/qnetworkproxy_generic.cpp @@ -57,30 +57,34 @@ static bool ignoreProxyFor(const QNetworkProxyQuery &query) if (noProxy.isEmpty()) return false; + const QString host = query.peerHostName(); + const QList noProxyTokens = noProxy.split(','); for (const QByteArray &rawToken : noProxyTokens) { - QByteArray token = rawToken.trimmed(); - QString peerHostName = query.peerHostName(); + auto token = QLatin1String(rawToken).trimmed(); // Since we use suffix matching, "*" is our 'default' behaviour - if (token.startsWith('*')) + if (token.startsWith(u'*')) token = token.mid(1); // Harmonize trailing dot notation - if (token.endsWith('.') && !peerHostName.endsWith('.')) - token = token.left(token.length()-1); + if (token.endsWith(u'.') && !host.endsWith(u'.')) + token = token.chopped(1); + + if (token.startsWith(u'.')) // leading dot is implied + token = token.mid(1); - // We prepend a dot to both values, so that when we do a suffix match, - // we don't match "donotmatch.com" with "match.com" - if (!token.startsWith('.')) - token.prepend('.'); + if (host.endsWith(token)) { - if (!peerHostName.startsWith('.')) - peerHostName.prepend('.'); + // Make sure that when we have a suffix match, + // we don't match "donotmatch.com" with "match.com" - if (peerHostName.endsWith(QLatin1String(token))) - return true; + if (host.size() == token.size()) // iow: host == token + return true; + if (host[host.size() - token.size() - 1] == u'.') // match follows a dot + return true; + } } return false; -- cgit v1.2.3