From 10b5590ce0f1085e04b9cc8e83071cb67d8bfb6f Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Mon, 29 May 2023 16:29:27 +0300 Subject: [PATCH] QFileInfoGatherer: fix narrowing conversion warnings Found by using -Wshorten-64-to-32 clang compiler flag, or adding that flag to the flags clangd uses. Drive-by changes: - Refactor a small while loop - Use reverse iterators - Move instead of copy while constructing a QList - Replace QPair by std::pair (see QTBUG-115841), and also for its CTAD, otherwise I'd have to spill the types out: updatedFiles.emplace_back(QPair{translateDriveName(driveInfo), std::move(driveInfo)}); otherwise the clangd complains: Alias template 'QPair' requires template arguments; argument deduction only allowed for class templates Task-number: QTBUG-115841 Pick-to: 6.5 Change-Id: I942459f039f6db23f7c1928fe758c6dbf339cd2b Reviewed-by: Volker Hilsheimer (cherry picked from commit 3cd69050ff3187dad8c3a9b50dcc9ac9d5b60f84) Reviewed-by: Qt Cherry-pick Bot --- src/gui/itemmodels/qfileinfogatherer.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/gui/itemmodels/qfileinfogatherer.cpp b/src/gui/itemmodels/qfileinfogatherer.cpp index 0e0a3b11a53..18afa1c62b0 100644 --- a/src/gui/itemmodels/qfileinfogatherer.cpp +++ b/src/gui/itemmodels/qfileinfogatherer.cpp @@ -13,6 +13,8 @@ # include "qplatformdefs.h" #endif +#include + QT_BEGIN_NAMESPACE using namespace Qt::StringLiterals; @@ -114,13 +116,12 @@ void QFileInfoGatherer::fetchExtendedInformation(const QString &path, const QStr { QMutexLocker locker(&mutex); // See if we already have this dir/file in our queue - int loc = this->path.lastIndexOf(path); - while (loc > 0) { - if (this->files.at(loc) == files) { + qsizetype loc = 0; + while ((loc = this->path.lastIndexOf(path, loc - 1)) != -1) { + if (this->files.at(loc) == files) return; - } - loc = this->path.lastIndexOf(path, loc - 1); } + #if QT_CONFIG(thread) this->path.push(path); this->files.push(files); @@ -348,13 +349,13 @@ void QFileInfoGatherer::getFileInfos(const QString &path, const QStringList &fil for (const auto &file : files) infoList << QFileInfo(file); } - QList> updatedFiles; + QList> updatedFiles; updatedFiles.reserve(infoList.size()); - for (int i = infoList.size() - 1; i >= 0; --i) { - QFileInfo driveInfo = infoList.at(i); + const auto rend = infoList.rend(); + for (auto rit = infoList.rbegin(); rit != rend; ++rit) { + QFileInfo &driveInfo = *rit; driveInfo.stat(); - QString driveName = translateDriveName(driveInfo); - updatedFiles.append(QPair(driveName, driveInfo)); + updatedFiles.emplace_back(std::pair{translateDriveName(driveInfo), std::move(driveInfo)}); } emit updates(path, updatedFiles); return;