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.5
Change-Id: I942459f039f6db23f7c1928fe758c6dbf339cd2b
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 3cd69050ff3187dad8c3a9b50dcc9ac9d5b60f84)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Ahmad Samir 2023-05-29 16:29:27 +03:00 committed by Qt Cherry-pick Bot
parent 4ec05ee2ad
commit 10b5590ce0

View File

@ -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;