From bd603b2eb8ebafa9c74a060a9f539e778ad97c05 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Tue, 18 Oct 2016 22:43:37 +0300 Subject: qhostaddress.cpp: optimize string usage Prefer QStringRef methods to avoid allocations. Change-Id: I0a5878f29c93e65feb2ab189b6b316d53ed497bd Reviewed-by: Edward Welbourne Reviewed-by: Thiago Macieira --- src/network/kernel/qhostaddress.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/network/kernel/qhostaddress.cpp') diff --git a/src/network/kernel/qhostaddress.cpp b/src/network/kernel/qhostaddress.cpp index 7e3d2c5d6e..2a905101a4 100644 --- a/src/network/kernel/qhostaddress.cpp +++ b/src/network/kernel/qhostaddress.cpp @@ -201,10 +201,10 @@ void QHostAddressPrivate::setAddress(const Q_IPV6ADDR &a_) static bool parseIp6(const QString &address, QIPAddressUtils::IPv6Address &addr, QString *scopeId) { - QString tmp = address; + QStringRef tmp(&address); int scopeIdPos = tmp.lastIndexOf(QLatin1Char('%')); if (scopeIdPos != -1) { - *scopeId = tmp.mid(scopeIdPos + 1); + *scopeId = tmp.mid(scopeIdPos + 1).toString(); tmp.chop(tmp.size() - scopeIdPos); } else { scopeId->clear(); @@ -1086,7 +1086,7 @@ QPair QHostAddress::parseSubnet(const QString &subnet) return invalid; int slash = subnet.indexOf(QLatin1Char('/')); - QString netStr = subnet; + QStringRef netStr(&subnet); if (slash != -1) netStr.truncate(slash); @@ -1117,7 +1117,7 @@ QPair QHostAddress::parseSubnet(const QString &subnet) netmask = 128; QHostAddress net; - if (!net.setAddress(netStr)) + if (!net.setAddress(netStr.toString())) return invalid; // failed to parse the IP clearBits(net.d->a6.c, netmask, 128); @@ -1128,7 +1128,7 @@ QPair QHostAddress::parseSubnet(const QString &subnet) return invalid; // invalid netmask // parse the address manually - auto parts = netStr.splitRef(QLatin1Char('.')); + auto parts = netStr.split(QLatin1Char('.')); if (parts.isEmpty() || parts.count() > 4) return invalid; // invalid IPv4 address -- cgit v1.2.3