summaryrefslogtreecommitdiffstats
path: root/src/network/kernel/qnetworkinterface_unix.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2020-06-04 17:39:20 +0200
committerMarc Mutz <marc.mutz@kdab.com>2020-06-08 19:01:51 +0200
commitf19522a1b3e5d1777b7a3ffde368e22f7e32df84 (patch)
tree261fc653e8db4c032464d0a6af993de128d35774 /src/network/kernel/qnetworkinterface_unix.cpp
parentfffaffb439403d19331894cc89fefe742c4deb51 (diff)
QNetworkInterface (Unix): port two local tracker (QSet/QLVA) to QDuplicateTracker
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 <marten.nordheim@qt.io>
Diffstat (limited to 'src/network/kernel/qnetworkinterface_unix.cpp')
-rw-r--r--src/network/kernel/qnetworkinterface_unix.cpp19
1 files changed, 9 insertions, 10 deletions
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 <QtCore/private/qduplicatetracker_p.h>
+
#ifndef QT_NO_NETWORKINTERFACE
#if defined(QT_NO_CLOCK_MONOTONIC)
@@ -344,8 +346,8 @@ static QList<QNetworkInterfacePrivate *> createInterfaces(ifaddrs *rawList)
{
Q_UNUSED(getMtu)
QList<QNetworkInterfacePrivate *> interfaces;
- QSet<QString> seenInterfaces;
- QVarLengthArray<int, 16> seenIndexes; // faster than QSet<int>
+ QDuplicateTracker<QString> seenInterfaces;
+ QDuplicateTracker<int> 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<QNetworkInterfacePrivate *> 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<QNetworkInterfacePrivate *> 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;