QDir: Refactor separate cache clearing functions into a single function

Task-number: QTBUG-105753
Change-Id: I7f3473ce21e71ccd04ff9f2575244167b5c3e3a4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Øystein Heskestad 2023-01-11 10:54:04 +01:00
parent c146d25a87
commit a5387f3c16
2 changed files with 13 additions and 25 deletions

View File

@ -153,19 +153,10 @@ inline void QDirPrivate::setPath(const QString &path)
} }
dirEntry = QFileSystemEntry(p, QFileSystemEntry::FromInternalPath()); dirEntry = QFileSystemEntry(p, QFileSystemEntry::FromInternalPath());
metaData.clear(); clearCache(IncludingMetaData);
initFileEngine();
clearFileLists();
absoluteDirEntry = QFileSystemEntry(); absoluteDirEntry = QFileSystemEntry();
} }
inline void QDirPrivate::clearFileLists()
{
fileListsInitialized = false;
files.clear();
fileInfos.clear();
}
inline void QDirPrivate::resolveAbsoluteEntry() const inline void QDirPrivate::resolveAbsoluteEntry() const
{ {
if (!absoluteDirEntry.isEmpty() || dirEntry.isEmpty()) 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)); fileEngine.reset(QFileSystemEngine::resolveEntryAndCreateLegacyEngine(dirEntry, metaData));
} }
@ -1014,9 +1010,7 @@ QStringList QDir::nameFilters() const
void QDir::setNameFilters(const QStringList &nameFilters) void QDir::setNameFilters(const QStringList &nameFilters)
{ {
Q_D(QDir); Q_D(QDir);
d->initFileEngine(); d->clearCache(QDirPrivate::KeepMetaData);
d->clearFileLists();
d->nameFilters = nameFilters; d->nameFilters = nameFilters;
} }
@ -1195,9 +1189,7 @@ QDir::Filters QDir::filter() const
void QDir::setFilter(Filters filters) void QDir::setFilter(Filters filters)
{ {
Q_D(QDir); Q_D(QDir);
d->initFileEngine(); d->clearCache(QDirPrivate::KeepMetaData);
d->clearFileLists();
d->filters = filters; d->filters = filters;
} }
@ -1252,9 +1244,7 @@ QDir::SortFlags QDir::sorting() const
void QDir::setSorting(SortFlags sort) void QDir::setSorting(SortFlags sort)
{ {
Q_D(QDir); Q_D(QDir);
d->initFileEngine(); d->clearCache(QDirPrivate::KeepMetaData);
d->clearFileLists();
d->sort = sort; d->sort = sort;
} }
@ -2352,9 +2342,7 @@ bool QDir::isRelativePath(const QString &path)
void QDir::refresh() const void QDir::refresh() const
{ {
QDirPrivate *d = const_cast<QDir *>(this)->d_func(); QDirPrivate *d = const_cast<QDir *>(this)->d_func();
d->metaData.clear(); d->clearCache(QDirPrivate::IncludingMetaData);
d->initFileEngine();
d->clearFileLists();
} }
/*! /*!

View File

@ -41,7 +41,6 @@ public:
bool exists() const; bool exists() const;
void initFileEngine();
void initFileLists(const QDir &dir) const; void initFileLists(const QDir &dir) const;
static void sortFileList(QDir::SortFlags, const QFileInfoList &, QStringList *, QFileInfoList *); static void sortFileList(QDir::SortFlags, const QFileInfoList &, QStringList *, QFileInfoList *);
@ -52,7 +51,8 @@ public:
void setPath(const QString &path); void setPath(const QString &path);
void clearFileLists(); enum MetaDataClearing { KeepMetaData, IncludingMetaData };
void clearCache(MetaDataClearing mode);
void resolveAbsoluteEntry() const; void resolveAbsoluteEntry() const;