From f19522a1b3e5d1777b7a3ffde368e22f7e32df84 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 4 Jun 2020 17:39:20 +0200 Subject: QNetworkInterface (Unix): port two local tracker (QSet/QLVA) to QDuplicateTracker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apart from a more fitting, minimal, API, QDuplicateTracker also transparently uses C++17 pmr::monotonic_buffer_resource to avoid, or at least reduce, memory allocations. Change-Id: I025504c7d22fb7a8c943e3968e4613d45c08d0b3 Reviewed-by: MÃ¥rten Nordheim --- src/network/kernel/qnetworkinterface_unix.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/network/kernel') diff --git a/src/network/kernel/qnetworkinterface_unix.cpp b/src/network/kernel/qnetworkinterface_unix.cpp index 4c57bff3bc..a6b0886bc6 100644 --- a/src/network/kernel/qnetworkinterface_unix.cpp +++ b/src/network/kernel/qnetworkinterface_unix.cpp @@ -45,6 +45,8 @@ #include "qnetworkinterface_unix_p.h" #include "qalgorithms.h" +#include + #ifndef QT_NO_NETWORKINTERFACE #if defined(QT_NO_CLOCK_MONOTONIC) @@ -344,8 +346,8 @@ static QList createInterfaces(ifaddrs *rawList) { Q_UNUSED(getMtu) QList interfaces; - QSet seenInterfaces; - QVarLengthArray seenIndexes; // faster than QSet + QDuplicateTracker seenInterfaces; + QDuplicateTracker seenIndexes; // On Linux, glibc, uClibc and MUSL obtain the address listing via two // netlink calls: first an RTM_GETLINK to obtain the interface listing, @@ -364,9 +366,9 @@ static QList createInterfaces(ifaddrs *rawList) iface->flags = convertFlags(ptr->ifa_flags); iface->hardwareAddress = iface->makeHwAddress(sll->sll_halen, (uchar*)sll->sll_addr); - Q_ASSERT(!seenIndexes.contains(iface->index)); - seenIndexes.append(iface->index); - seenInterfaces.insert(iface->name); + const bool sawIfaceIndex = seenIndexes.hasSeen(iface->index); + Q_ASSERT(!sawIfaceIndex); + (void)seenInterfaces.hasSeen(iface->name); } } @@ -376,16 +378,13 @@ static QList createInterfaces(ifaddrs *rawList) for (ifaddrs *ptr = rawList; ptr; ptr = ptr->ifa_next) { if (!ptr->ifa_addr || ptr->ifa_addr->sa_family != AF_PACKET) { QString name = QString::fromLatin1(ptr->ifa_name); - if (seenInterfaces.contains(name)) + if (seenInterfaces.hasSeen(name)) continue; int ifindex = if_nametoindex(ptr->ifa_name); - if (seenIndexes.contains(ifindex)) + if (seenIndexes.hasSeen(ifindex)) continue; - seenInterfaces.insert(name); - seenIndexes.append(ifindex); - QNetworkInterfacePrivate *iface = new QNetworkInterfacePrivate; interfaces << iface; iface->name = name; -- cgit v1.2.3