From 37917b94615ee448101a38ba9f589fd992716a63 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Wed, 9 Dec 2020 10:44:36 -0800 Subject: QUrl: improve parseIp6's use of QStringView Change-Id: I55083c2909f64a1f8868fffd164f20a2fb8ff7f6 Reviewed-by: David Faure --- src/corelib/io/qurl.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp index 67f549036c..c303cfb13e 100644 --- a/src/corelib/io/qurl.cpp +++ b/src/corelib/io/qurl.cpp @@ -1252,12 +1252,10 @@ static const QChar *parseIp6(QString &host, const QChar *begin, const QChar *end QIPAddressUtils::IPv6Address address; QStringView zoneId; - const QChar *endBeforeZoneId = decoded.constEnd(); - int zoneIdPosition = decoded.indexOf(zoneIdIdentifier); if ((zoneIdPosition != -1) && (decoded.lastIndexOf(zoneIdIdentifier) == zoneIdPosition)) { zoneId = decoded.mid(zoneIdPosition + zoneIdIdentifier.size()); - endBeforeZoneId = decoded.constBegin() + zoneIdPosition; + decoded.truncate(zoneIdPosition); // was there anything after the zone ID separator? if (zoneId.isEmpty()) @@ -1266,14 +1264,14 @@ static const QChar *parseIp6(QString &host, const QChar *begin, const QChar *end // did the address become empty after removing the zone ID? // (it might have always been empty) - if (decoded.constBegin() == endBeforeZoneId) + if (decoded.isEmpty()) return end; - const QChar *ret = QIPAddressUtils::parseIp6(address, decoded.constBegin(), endBeforeZoneId); + const QChar *ret = QIPAddressUtils::parseIp6(address, decoded.constBegin(), decoded.constEnd()); if (ret) return begin + (ret - decoded.constBegin()); - host.reserve(host.size() + (decoded.constEnd() - decoded.constBegin())); + host.reserve(host.size() + (end - begin) + 2); // +2 for the brackets host += QLatin1Char('['); QIPAddressUtils::toString(host, address); -- cgit v1.2.3