QDirIterator: port visitedLinks from QSet 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 old code performed the visitedLinks check unconditionally, but
since we add entries to visitedLinks only when following symlinks (and
this property cannot be changed under iteration, as `iteratorFlags` is
a const member), the new code only performs the check conditionally,
with unchanged semantics.

Change-Id: Ia2c2dda16136ef5256e2c345b8ecba530883ee37
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Marc Mutz 2020-05-02 23:03:39 +02:00
parent 1ba42c10bb
commit 0f2869fcdc
1 changed files with 7 additions and 7 deletions

View File

@ -108,6 +108,7 @@
#include <QtCore/private/qfilesystemmetadata_p.h>
#include <QtCore/private/qfilesystemengine_p.h>
#include <QtCore/private/qfileinfo_p.h>
#include <QtCore/private/qduplicatetracker_p.h>
#include <memory>
@ -159,7 +160,7 @@ public:
QFileInfo nextFileInfo;
// Loop protection
QSet<QString> visitedLinks;
QDuplicateTracker<QString> visitedLinks;
};
/*!
@ -210,12 +211,11 @@ void QDirIteratorPrivate::pushDirectory(const QFileInfo &fileInfo)
path = fileInfo.canonicalFilePath();
#endif
// Stop link loops
if (visitedLinks.contains(fileInfo.canonicalFilePath()))
return;
if (iteratorFlags & QDirIterator::FollowSymlinks)
visitedLinks << fileInfo.canonicalFilePath();
if ((iteratorFlags & QDirIterator::FollowSymlinks)) {
// Stop link loops
if (visitedLinks.hasSeen(fileInfo.canonicalFilePath()))
return;
}
if (engine) {
engine->setFileName(path);