mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-18 06:28:03 -06:00
Use proper return type
`count()`, `length()`, `size()`, `indexOf()` and `lastIndexOf()` were returning `int` in Qt5. In Qt6 they return `qsizetype`. PR #23317.
This commit is contained in:
@@ -170,8 +170,8 @@ namespace
|
||||
|
||||
std::pair<QString, QString> joinColumns(const QList<Column> &columns)
|
||||
{
|
||||
int namesSize = columns.size();
|
||||
int valuesSize = columns.size();
|
||||
qsizetype namesSize = columns.size();
|
||||
qsizetype valuesSize = columns.size();
|
||||
for (const Column &column : columns)
|
||||
{
|
||||
namesSize += column.name.size() + 2;
|
||||
|
||||
@@ -273,12 +273,12 @@ QString PeerInfo::connectionType() const
|
||||
|
||||
qreal PeerInfo::calcRelevance(const QBitArray &allPieces) const
|
||||
{
|
||||
const int localMissing = allPieces.count(false);
|
||||
const qsizetype localMissing = allPieces.count(false);
|
||||
if (localMissing <= 0)
|
||||
return 0;
|
||||
|
||||
const QBitArray peerPieces = pieces();
|
||||
const int remoteHaves = (peerPieces & (~allPieces)).count(true);
|
||||
const qsizetype remoteHaves = (peerPieces & (~allPieces)).count(true);
|
||||
return static_cast<qreal>(remoteHaves) / localMissing;
|
||||
}
|
||||
|
||||
|
||||
@@ -404,7 +404,7 @@ bool Session::isValidCategoryName(const QString &name)
|
||||
|
||||
QString Session::subcategoryName(const QString &category)
|
||||
{
|
||||
const int sepIndex = category.lastIndexOf(u'/');
|
||||
const qsizetype sepIndex = category.lastIndexOf(u'/');
|
||||
if (sepIndex >= 0)
|
||||
return category.sliced(sepIndex + 1);
|
||||
|
||||
@@ -413,7 +413,7 @@ QString Session::subcategoryName(const QString &category)
|
||||
|
||||
QString Session::parentCategoryName(const QString &category)
|
||||
{
|
||||
const int sepIndex = category.lastIndexOf(u'/');
|
||||
const qsizetype sepIndex = category.lastIndexOf(u'/');
|
||||
if (sepIndex >= 0)
|
||||
return category.first(sepIndex);
|
||||
|
||||
@@ -2843,7 +2843,7 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr
|
||||
|
||||
if (!filePriorities.isEmpty())
|
||||
{
|
||||
for (int i = 0; i < filePriorities.size(); ++i)
|
||||
for (qsizetype i = 0; i < filePriorities.size(); ++i)
|
||||
p.file_priorities[LT::toUnderlyingType(nativeIndexes[i])] = LT::toNative(filePriorities[i]);
|
||||
}
|
||||
|
||||
@@ -2944,7 +2944,7 @@ bool SessionImpl::addTorrent_impl(const TorrentDescriptor &source, const AddTorr
|
||||
{
|
||||
const TorrentInfo torrentInfo {*p.ti};
|
||||
const auto nativeIndexes = torrentInfo.nativeIndexes();
|
||||
for (int i = 0; i < result.fileNames.size(); ++i)
|
||||
for (qsizetype i = 0; i < result.fileNames.size(); ++i)
|
||||
p.renamed_files[nativeIndexes[i]] = result.fileNames[i].toString().toStdString();
|
||||
}
|
||||
|
||||
@@ -4146,7 +4146,7 @@ void SessionImpl::applyFilenameFilter(const PathList &files, QList<DownloadPrior
|
||||
};
|
||||
|
||||
priorities.resize(files.count(), DownloadPriority::Normal);
|
||||
for (int i = 0; i < priorities.size(); ++i)
|
||||
for (qsizetype i = 0; i < priorities.size(); ++i)
|
||||
{
|
||||
if (priorities[i] == BitTorrent::DownloadPriority::Ignored)
|
||||
continue;
|
||||
|
||||
@@ -57,9 +57,10 @@ namespace
|
||||
// == 20 (SHA-1 length in bytes) * 1.6 (the efficiency of Base32 encoding)
|
||||
const int V1_HEX_SIZE = SHA1Hash::length() * 2;
|
||||
const int V1_BASE32_SIZE = SHA1Hash::length() * 1.6;
|
||||
const qsizetype strSize = string.size();
|
||||
|
||||
return ((((string.size() == V1_HEX_SIZE)) && !string.contains(QRegularExpression(u"[^0-9A-Fa-f]"_s)))
|
||||
|| ((string.size() == V1_BASE32_SIZE) && !string.contains(QRegularExpression(u"[^2-7A-Za-z]"_s))));
|
||||
return (((strSize == V1_HEX_SIZE) && !string.contains(QRegularExpression(u"[^0-9A-Fa-f]"_s)))
|
||||
|| ((strSize == V1_BASE32_SIZE) && !string.contains(QRegularExpression(u"[^2-7A-Za-z]"_s))));
|
||||
}
|
||||
|
||||
bool isV2Hash(const QString &string)
|
||||
|
||||
@@ -1403,7 +1403,7 @@ QList<qreal> TorrentImpl::filesProgress() const
|
||||
if (!hasMetadata())
|
||||
return {};
|
||||
|
||||
const int count = m_filesProgress.size();
|
||||
const qsizetype count = m_filesProgress.size();
|
||||
Q_ASSERT(count == filesCount());
|
||||
if (count != filesCount()) [[unlikely]]
|
||||
return {};
|
||||
@@ -1710,7 +1710,7 @@ void TorrentImpl::applyFirstLastPiecePriority(const bool enabled)
|
||||
|
||||
// Updating file priorities is an async operation in libtorrent, when we just updated it and immediately query it
|
||||
// we might get the old/wrong values, so we rely on `updatedFilePrio` in this case.
|
||||
for (int fileIndex = 0; fileIndex < m_filePriorities.size(); ++fileIndex)
|
||||
for (qsizetype fileIndex = 0; fileIndex < m_filePriorities.size(); ++fileIndex)
|
||||
{
|
||||
const DownloadPriority filePrio = m_filePriorities[fileIndex];
|
||||
if (filePrio <= DownloadPriority::Ignored)
|
||||
@@ -1808,7 +1808,7 @@ void TorrentImpl::endReceivedMetadataHandling(const Path &savePath, const PathLi
|
||||
m_filesProgress.resize(filesCount());
|
||||
updateProgress();
|
||||
|
||||
for (int i = 0; i < fileNames.size(); ++i)
|
||||
for (qsizetype i = 0; i < fileNames.size(); ++i)
|
||||
{
|
||||
const auto nativeIndex = nativeIndexes.at(i);
|
||||
|
||||
@@ -1822,7 +1822,7 @@ void TorrentImpl::endReceivedMetadataHandling(const Path &savePath, const PathLi
|
||||
}
|
||||
|
||||
m_session->applyFilenameFilter(m_filePaths, m_filePriorities);
|
||||
for (int i = 0; i < m_filePriorities.size(); ++i)
|
||||
for (qsizetype i = 0; i < m_filePriorities.size(); ++i)
|
||||
p.file_priorities[LT::toUnderlyingType(nativeIndexes[i])] = LT::toNative(m_filePriorities[i]);
|
||||
|
||||
p.save_path = savePath.toString().toStdString();
|
||||
@@ -2152,7 +2152,7 @@ void TorrentImpl::handleSaveResumeData(lt::add_torrent_params params)
|
||||
|
||||
const auto nativeIndexes = metadata.nativeIndexes();
|
||||
m_indexMap.reserve(filePaths.size());
|
||||
for (int i = 0; i < filePaths.size(); ++i)
|
||||
for (qsizetype i = 0; i < filePaths.size(); ++i)
|
||||
{
|
||||
const auto nativeIndex = nativeIndexes.at(i);
|
||||
m_indexMap[nativeIndex] = i;
|
||||
@@ -2931,7 +2931,7 @@ void TorrentImpl::prioritizeFiles(const QList<DownloadPriority> &priorities)
|
||||
// Reset 'm_hasSeedStatus' if needed in order to react again to
|
||||
// "torrent finished" event and e.g. show tray notifications
|
||||
const QList<DownloadPriority> oldPriorities = filePriorities();
|
||||
for (int i = 0; i < oldPriorities.size(); ++i)
|
||||
for (qsizetype i = 0; i < oldPriorities.size(); ++i)
|
||||
{
|
||||
if ((oldPriorities[i] == DownloadPriority::Ignored)
|
||||
&& (priorities[i] > DownloadPriority::Ignored)
|
||||
@@ -2945,7 +2945,7 @@ void TorrentImpl::prioritizeFiles(const QList<DownloadPriority> &priorities)
|
||||
const int internalFilesCount = m_torrentInfo.nativeInfo()->files().num_files(); // including .pad files
|
||||
auto nativePriorities = std::vector<lt::download_priority_t>(internalFilesCount, LT::toNative(DownloadPriority::Normal));
|
||||
const auto nativeIndexes = m_torrentInfo.nativeIndexes();
|
||||
for (int i = 0; i < priorities.size(); ++i)
|
||||
for (qsizetype i = 0; i < priorities.size(); ++i)
|
||||
nativePriorities[LT::toUnderlyingType(nativeIndexes[i])] = LT::toNative(priorities[i]);
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Changing files priorities...";
|
||||
|
||||
@@ -184,7 +184,7 @@ QByteArray TorrentInfo::rawData() const
|
||||
if (!isValid()) return {};
|
||||
#ifdef QBT_USES_LIBTORRENT2
|
||||
const lt::span<const char> infoSection {m_nativeInfo->info_section()};
|
||||
return {infoSection.data(), static_cast<int>(infoSection.size())};
|
||||
return {infoSection.data(), static_cast<qsizetype>(infoSection.size())};
|
||||
#else
|
||||
return {m_nativeInfo->metadata().get(), m_nativeInfo->metadata_size()};
|
||||
#endif
|
||||
@@ -214,7 +214,7 @@ QList<int> TorrentInfo::fileIndicesForPiece(const int pieceIndex) const
|
||||
res.reserve(static_cast<decltype(res)::size_type>(files.size()));
|
||||
for (const lt::file_slice &fileSlice : files)
|
||||
{
|
||||
const int index = m_nativeIndexes.indexOf(fileSlice.file_index);
|
||||
const qsizetype index = m_nativeIndexes.indexOf(fileSlice.file_index);
|
||||
if (index >= 0)
|
||||
res.append(index);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user