Switch to C++20

PR #19336.
This commit is contained in:
Vladimir Golovnev
2023-07-21 15:38:49 +03:00
committed by GitHub
parent f27f2c20e0
commit 10ee1ab7a2
15 changed files with 24 additions and 48 deletions

View File

@@ -118,7 +118,7 @@ void CustomDiskIOThread::async_move_storage(lt::storage_index_t storage, std::st
handleCompleteFiles(storage, newSavePath);
m_nativeDiskIO->async_move_storage(storage, path, flags
, [=, handler = std::move(handler)](lt::status_t status, const std::string &path, const lt::storage_error &error)
, [=, this, handler = std::move(handler)](lt::status_t status, const std::string &path, const lt::storage_error &error)
{
#if LIBTORRENT_VERSION_NUM < 20100
if ((status != lt::status_t::fatal_disk_error) && (status != lt::status_t::file_exist))
@@ -153,7 +153,7 @@ void CustomDiskIOThread::async_rename_file(lt::storage_index_t storage, lt::file
, std::function<void (const std::string &, lt::file_index_t, const lt::storage_error &)> handler)
{
m_nativeDiskIO->async_rename_file(storage, index, name
, [=, handler = std::move(handler)](const std::string &name, lt::file_index_t index, const lt::storage_error &error)
, [=, this, handler = std::move(handler)](const std::string &name, lt::file_index_t index, const lt::storage_error &error)
{
if (!error)
m_storageData[storage].files.rename_file(index, name);
@@ -171,7 +171,7 @@ void CustomDiskIOThread::async_set_file_priority(lt::storage_index_t storage, lt
, std::function<void (const lt::storage_error &, lt::aux::vector<lt::download_priority_t, lt::file_index_t>)> handler)
{
m_nativeDiskIO->async_set_file_priority(storage, std::move(priorities)
, [=, handler = std::move(handler)](const lt::storage_error &error, const lt::aux::vector<lt::download_priority_t, lt::file_index_t> &priorities)
, [=, this, handler = std::move(handler)](const lt::storage_error &error, const lt::aux::vector<lt::download_priority_t, lt::file_index_t> &priorities)
{
m_storageData[storage].filePriorities = priorities;
handler(error, priorities);

View File

@@ -2904,7 +2904,7 @@ void SessionImpl::findIncompleteFiles(const TorrentInfo &torrentInfo, const Path
const auto searchId = TorrentID::fromInfoHash(torrentInfo.infoHash());
const PathList originalFileNames = (filePaths.isEmpty() ? torrentInfo.filePaths() : filePaths);
QMetaObject::invokeMethod(m_fileSearcher, [=]()
QMetaObject::invokeMethod(m_fileSearcher, [=, this]
{
m_fileSearcher->search(searchId, originalFileNames, savePath, downloadPath, isAppendExtensionEnabled());
});

View File

@@ -1217,7 +1217,7 @@ QVector<qreal> TorrentImpl::filesProgress() const
const int count = m_filesProgress.size();
Q_ASSERT(count == filesCount());
if (Q_UNLIKELY(count != filesCount()))
if (count != filesCount()) [[unlikely]]
return {};
if (m_completedFiles.count(true) == count)
@@ -1613,8 +1613,7 @@ TrackerEntry TorrentImpl::updateTrackerEntry(const lt::announce_entry &announceE
});
Q_ASSERT(it != m_trackerEntries.end());
// TODO: use [[unlikely]] in C++20
if (Q_UNLIKELY(it == m_trackerEntries.end()))
if (it == m_trackerEntries.end()) [[unlikely]]
return {};
#ifdef QBT_USES_LIBTORRENT2
@@ -1813,7 +1812,7 @@ void TorrentImpl::moveStorage(const Path &newPath, const MoveStorageContext cont
void TorrentImpl::renameFile(const int index, const Path &path)
{
Q_ASSERT((index >= 0) && (index < filesCount()));
if (Q_UNLIKELY((index < 0) || (index >= filesCount())))
if ((index < 0) || (index >= filesCount())) [[unlikely]]
return;
const Path wantedPath = wantedActualPath(index, path);
@@ -2276,7 +2275,7 @@ void TorrentImpl::doRenameFile(int index, const Path &path)
Q_ASSERT(index >= 0);
Q_ASSERT(index < nativeIndexes.size());
if (Q_UNLIKELY((index < 0) || (index >= nativeIndexes.size())))
if ((index < 0) || (index >= nativeIndexes.size())) [[unlikely]]
return;
++m_renameCount;
@@ -2364,11 +2363,11 @@ void TorrentImpl::updateStatus(const lt::torrent_status &nativeStatus)
void TorrentImpl::updateProgress()
{
Q_ASSERT(hasMetadata());
if (Q_UNLIKELY(!hasMetadata()))
if (!hasMetadata()) [[unlikely]]
return;
Q_ASSERT(!m_filesProgress.isEmpty());
if (Q_UNLIKELY(m_filesProgress.isEmpty()))
if (m_filesProgress.isEmpty()) [[unlikely]]
m_filesProgress.resize(filesCount());
const QBitArray oldPieces = std::exchange(m_pieces, LT::toQBitArray(m_nativeStatus.pieces));

View File

@@ -74,12 +74,12 @@ void Connection::read()
const qint64 bytesAvailable = m_socket->bytesAvailable();
m_receivedData.resize(previousSize + bytesAvailable);
const qint64 bytesRead = m_socket->read((m_receivedData.data() + previousSize), bytesAvailable);
if (Q_UNLIKELY(bytesRead < 0))
if (bytesRead < 0) [[unlikely]]
{
m_socket->close();
return;
}
if (Q_UNLIKELY(bytesRead < bytesAvailable))
if (bytesRead < bytesAvailable) [[unlikely]]
m_receivedData.chop(bytesAvailable - bytesRead);
while (!m_receivedData.isEmpty())

View File

@@ -51,13 +51,6 @@ public:
// The following are custom functions that are in line with Qt API interface, such as `QSet`
#if __cplusplus < 202002L
bool contains(const key_type &value) const
{
return (BaseType::find(value) != BaseType::cend());
}
#endif
int count() const
{
return static_cast<int>(BaseType::size());

View File

@@ -524,8 +524,7 @@ void Feed::handleArticleLoadFinished(QVector<QVariantHash> articles)
for (const QVariantHash &articleData : articles)
{
const auto articleID = articleData.value(Article::KeyId).toString();
// TODO: use [[unlikely]] in C++20
if (Q_UNLIKELY(m_articles.contains(articleID)))
if (m_articles.contains(articleID)) [[unlikely]]
continue;
auto *article = new Article(this, articleData);