From a5387f3c1663be15395fbbd574d74c13e22171b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Heskestad?= Date: Wed, 11 Jan 2023 10:54:04 +0100 Subject: [PATCH] QDir: Refactor separate cache clearing functions into a single function Task-number: QTBUG-105753 Change-Id: I7f3473ce21e71ccd04ff9f2575244167b5c3e3a4 Reviewed-by: Thiago Macieira --- src/corelib/io/qdir.cpp | 34 +++++++++++----------------------- src/corelib/io/qdir_p.h | 4 ++-- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index 2d6b6e6f22..8529cf1dd2 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -153,19 +153,10 @@ inline void QDirPrivate::setPath(const QString &path) } dirEntry = QFileSystemEntry(p, QFileSystemEntry::FromInternalPath()); - metaData.clear(); - initFileEngine(); - clearFileLists(); + clearCache(IncludingMetaData); absoluteDirEntry = QFileSystemEntry(); } -inline void QDirPrivate::clearFileLists() -{ - fileListsInitialized = false; - files.clear(); - fileInfos.clear(); -} - inline void QDirPrivate::resolveAbsoluteEntry() const { if (!absoluteDirEntry.isEmpty() || dirEntry.isEmpty()) @@ -316,8 +307,13 @@ inline void QDirPrivate::initFileLists(const QDir &dir) const } } -inline void QDirPrivate::initFileEngine() +inline void QDirPrivate::clearCache(MetaDataClearing mode) { + if (mode == IncludingMetaData) + metaData.clear(); + fileListsInitialized = false; + files.clear(); + fileInfos.clear(); fileEngine.reset(QFileSystemEngine::resolveEntryAndCreateLegacyEngine(dirEntry, metaData)); } @@ -1014,9 +1010,7 @@ QStringList QDir::nameFilters() const void QDir::setNameFilters(const QStringList &nameFilters) { Q_D(QDir); - d->initFileEngine(); - d->clearFileLists(); - + d->clearCache(QDirPrivate::KeepMetaData); d->nameFilters = nameFilters; } @@ -1195,9 +1189,7 @@ QDir::Filters QDir::filter() const void QDir::setFilter(Filters filters) { Q_D(QDir); - d->initFileEngine(); - d->clearFileLists(); - + d->clearCache(QDirPrivate::KeepMetaData); d->filters = filters; } @@ -1252,9 +1244,7 @@ QDir::SortFlags QDir::sorting() const void QDir::setSorting(SortFlags sort) { Q_D(QDir); - d->initFileEngine(); - d->clearFileLists(); - + d->clearCache(QDirPrivate::KeepMetaData); d->sort = sort; } @@ -2352,9 +2342,7 @@ bool QDir::isRelativePath(const QString &path) void QDir::refresh() const { QDirPrivate *d = const_cast(this)->d_func(); - d->metaData.clear(); - d->initFileEngine(); - d->clearFileLists(); + d->clearCache(QDirPrivate::IncludingMetaData); } /*! diff --git a/src/corelib/io/qdir_p.h b/src/corelib/io/qdir_p.h index 9f6be858e5..415f8e2ce6 100644 --- a/src/corelib/io/qdir_p.h +++ b/src/corelib/io/qdir_p.h @@ -41,7 +41,6 @@ public: bool exists() const; - void initFileEngine(); void initFileLists(const QDir &dir) const; static void sortFileList(QDir::SortFlags, const QFileInfoList &, QStringList *, QFileInfoList *); @@ -52,7 +51,8 @@ public: void setPath(const QString &path); - void clearFileLists(); + enum MetaDataClearing { KeepMetaData, IncludingMetaData }; + void clearCache(MetaDataClearing mode); void resolveAbsoluteEntry() const;