From b9b7f44563316af3fbd93d18d11964f68243dd05 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Tue, 14 Feb 2023 21:49:13 +0200 Subject: [PATCH] QDir: when sorting use the cached filename if it was assigned to After commit b5a54d488cfc94a3, we now use QCollator and so no toLower() when caching the filename, we can re-use it from the cache after sorting. Change-Id: I8602a11c6f68cfe61db3ec6330596066cd257dab Reviewed-by: Thiago Macieira --- src/corelib/io/qdir.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/corelib/io/qdir.cpp b/src/corelib/io/qdir.cpp index f55cf6b5f9..d560f67c0e 100644 --- a/src/corelib/io/qdir.cpp +++ b/src/corelib/io/qdir.cpp @@ -330,13 +330,17 @@ inline void QDirPrivate::sortFileList(QDir::SortFlags sort, const QFileInfoList // put them back in the list(s) for (qsizetype i = 0; i < n; ++i) { + auto &fileInfo = si[i].item; if (infos) - infos->append(si[i].item); - if (names) - names->append(si[i].item.fileName()); + infos->append(fileInfo); + if (names) { + const bool cached = !si[i].filename_cache.isNull(); + names->append(cached ? si[i].filename_cache : fileInfo.fileName()); + } } } } + inline void QDirPrivate::initFileLists(const QDir &dir) const { QMutexLocker locker(&fileCache.mutex);