QSsl: port a local QStringList 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.

The code is the first user of the collected data, so make that
available by adding QDuplicateTracker::appendTo(Container&) methods.

Change-Id: Ibd8810c0070db7e6b3ead6d6a569facdab88b646
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Marc Mutz 2020-06-04 17:39:20 +02:00
parent 48b1bc48f1
commit 6ec41bd550
2 changed files with 19 additions and 4 deletions

View File

@ -99,6 +99,20 @@ public:
#endif #endif
return !inserted; return !inserted;
} }
template <typename C>
void appendTo(C &c) const &
{
for (const auto &e : set)
c.push_back(e);
}
template <typename C>
void appendTo(C &c) &&
{
for (auto &e : set)
c.push_back(std::move(e));
}
}; };
QT_END_NAMESPACE QT_END_NAMESPACE

View File

@ -68,6 +68,7 @@
#include <QtCore/qdir.h> #include <QtCore/qdir.h>
#endif #endif
#include <QtCore/private/qmemory_p.h> #include <QtCore/private/qmemory_p.h>
#include <QtCore/private/qduplicatetracker_p.h>
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID) #if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
#include <link.h> #include <link.h>
#endif #endif
@ -569,13 +570,13 @@ static int dlIterateCallback(struct dl_phdr_info *info, size_t size, void *data)
{ {
if (size < sizeof (info->dlpi_addr) + sizeof (info->dlpi_name)) if (size < sizeof (info->dlpi_addr) + sizeof (info->dlpi_name))
return 1; return 1;
QSet<QString> *paths = (QSet<QString> *)data; QDuplicateTracker<QString> *paths = (QDuplicateTracker<QString> *)data;
QString path = QString::fromLocal8Bit(info->dlpi_name); QString path = QString::fromLocal8Bit(info->dlpi_name);
if (!path.isEmpty()) { if (!path.isEmpty()) {
QFileInfo fi(path); QFileInfo fi(path);
path = fi.absolutePath(); path = fi.absolutePath();
if (!path.isEmpty()) if (!path.isEmpty())
paths->insert(path); (void)paths->hasSeen(std::move(path));
} }
return 0; return 0;
} }
@ -608,9 +609,9 @@ static QStringList libraryPathList()
paths << QLatin1String("/system/lib"); paths << QLatin1String("/system/lib");
#elif defined(Q_OS_LINUX) #elif defined(Q_OS_LINUX)
// discover paths of already loaded libraries // discover paths of already loaded libraries
QSet<QString> loadedPaths; QDuplicateTracker<QString> loadedPaths;
dl_iterate_phdr(dlIterateCallback, &loadedPaths); dl_iterate_phdr(dlIterateCallback, &loadedPaths);
paths.append(loadedPaths.values()); std::move(loadedPaths).appendTo(paths);
#endif #endif
return paths; return paths;