summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Samir <[email protected]>2023-05-29 16:29:27 +0300
committerAhmad Samir <[email protected]>2023-12-06 18:55:07 +0300
commit3cd69050ff3187dad8c3a9b50dcc9ac9d5b60f84 (patch)
treefda5d8c2f892eb0cbfe8c38eff2df91e370b4eec
parent2f6fe3a26843ff68c5d3f9af0a2fc3cce6caac22 (diff)
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<QString,QFileInfo>{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.6 6.5 Change-Id: I942459f039f6db23f7c1928fe758c6dbf339cd2b Reviewed-by: Volker Hilsheimer <[email protected]>
-rw-r--r--src/gui/itemmodels/qfileinfogatherer.cpp21
1 files 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 <utility>
+
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<QPair<QString, QFileInfo>> updatedFiles;
+ QList<std::pair<QString, QFileInfo>> 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<QString,QFileInfo>(driveName, driveInfo));
+ updatedFiles.emplace_back(std::pair{translateDriveName(driveInfo), std::move(driveInfo)});
}
emit updates(path, updatedFiles);
return;