QDir::entryList: don't fill a QFileInfo cache if we just want names
This improves the performance of tst_QDir_10000::iDontWantAnyStat (QDir::entryList Unsorted) from 9.7ms to 7.2ms, i.e. the same as iDontWantAnyStatIterator (QDirIterator). Change-Id: I3faf8af1a55575df97912b1ce720492c8fd903c9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
eae031d5c3
commit
94057bd800
@ -100,7 +100,7 @@ QDirPrivate::QDirPrivate(const QDirPrivate ©)
|
||||
dirEntry(copy.dirEntry)
|
||||
{
|
||||
QMutexLocker locker(©.fileCache.mutex);
|
||||
fileCache.fileListsInitialized = copy.fileCache.fileListsInitialized;
|
||||
fileCache.fileListsInitialized = copy.fileCache.fileListsInitialized.load();
|
||||
fileCache.files = copy.fileCache.files;
|
||||
fileCache.fileInfos = copy.fileCache.fileInfos;
|
||||
fileCache.absoluteDirEntry = copy.fileCache.absoluteDirEntry;
|
||||
@ -1378,17 +1378,29 @@ QStringList QDir::entryList(const QStringList &nameFilters, Filters filters,
|
||||
if (sort == NoSort)
|
||||
sort = d->sort;
|
||||
|
||||
const bool needsSorting = (sort & QDir::SortByMask) != QDir::Unsorted;
|
||||
|
||||
if (filters == d->filters && sort == d->sort && nameFilters == d->nameFilters) {
|
||||
d->initFileLists(*this);
|
||||
return d->fileCache.files;
|
||||
// Don't fill a QFileInfo cache if we just need names
|
||||
if (needsSorting || d->fileCache.fileListsInitialized) {
|
||||
d->initFileLists(*this);
|
||||
return d->fileCache.files;
|
||||
}
|
||||
}
|
||||
|
||||
QFileInfoList l;
|
||||
QDirIterator it(d->dirEntry.filePath(), nameFilters, filters);
|
||||
while (it.hasNext())
|
||||
l.append(it.nextFileInfo());
|
||||
QStringList ret;
|
||||
d->sortFileList(sort, l, &ret, nullptr);
|
||||
if (needsSorting) {
|
||||
QFileInfoList l;
|
||||
while (it.hasNext())
|
||||
l.append(it.nextFileInfo());
|
||||
d->sortFileList(sort, l, &ret, nullptr);
|
||||
} else {
|
||||
while (it.hasNext()) {
|
||||
it.next();
|
||||
ret.append(it.fileName());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -71,7 +71,7 @@ public:
|
||||
QMutex mutex;
|
||||
QStringList files;
|
||||
QFileInfoList fileInfos;
|
||||
bool fileListsInitialized = false;
|
||||
std::atomic<bool> fileListsInitialized = false;
|
||||
QFileSystemEntry absoluteDirEntry;
|
||||
QFileSystemMetaData metaData;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user