From 63043b49277631ea58eb929566fbb6bfbed18a6c Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 27 Dec 2021 20:31:57 +0800 Subject: [PATCH] Replace min, max, clamp functions with std counterparts --- src/base/bittorrent/session.cpp | 16 ++++++++-------- src/base/bittorrent/torrentimpl.cpp | 2 +- src/gui/addnewtorrentdialog.cpp | 4 +++- src/gui/properties/downloadedpiecesbar.cpp | 3 ++- src/gui/properties/pieceavailabilitybar.cpp | 7 ++++--- src/gui/speedlimitdialog.cpp | 18 ++++++++++-------- src/gui/torrentoptionsdialog.cpp | 14 ++++++++------ 7 files changed, 36 insertions(+), 28 deletions(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 4d5d0638f..097e554b0 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -3171,7 +3171,7 @@ void Session::setPeerTurnoverInterval(const int val) int Session::asyncIOThreads() const { - return qBound(1, m_asyncIOThreads.get(), 1024); + return std::clamp(m_asyncIOThreads.get(), 1, 1024); } void Session::setAsyncIOThreads(const int num) @@ -3185,7 +3185,7 @@ void Session::setAsyncIOThreads(const int num) int Session::hashingThreads() const { - return qBound(1, m_hashingThreads.get(), 1024); + return std::clamp(m_hashingThreads.get(), 1, 1024); } void Session::setHashingThreads(const int num) @@ -3213,12 +3213,12 @@ void Session::setFilePoolSize(const int size) int Session::checkingMemUsage() const { - return qMax(1, m_checkingMemUsage.get()); + return std::max(1, m_checkingMemUsage.get()); } void Session::setCheckingMemUsage(int size) { - size = qMax(size, 1); + size = std::max(size, 1); if (size == m_checkingMemUsage) return; @@ -3230,21 +3230,21 @@ void Session::setCheckingMemUsage(int size) int Session::diskCacheSize() const { #ifdef QBT_APP_64BIT - return qMin(m_diskCacheSize.get(), 33554431); // 32768GiB + return std::min(m_diskCacheSize.get(), 33554431); // 32768GiB #else // When build as 32bit binary, set the maximum at less than 2GB to prevent crashes // allocate 1536MiB and leave 512MiB to the rest of program data in RAM - return qMin(m_diskCacheSize.get(), 1536); + return std::min(m_diskCacheSize.get(), 1536); #endif } void Session::setDiskCacheSize(int size) { #ifdef QBT_APP_64BIT - size = qMin(size, 33554431); // 32768GiB + size = std::min(size, 33554431); // 32768GiB #else // allocate 1536MiB and leave 512MiB to the rest of program data in RAM - size = qMin(size, 1536); + size = std::min(size, 1536); #endif if (size != m_diskCacheSize) { diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index 83f133591..807b93363 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -1063,7 +1063,7 @@ qlonglong TorrentImpl::eta() const seedingTimeEta = 0; } - return qMin(ratioEta, seedingTimeEta); + return std::min(ratioEta, seedingTimeEta); } if (!speedAverage.download) return MAX_ETA; diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index e97fa0180..f9a8a0a0b 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -28,6 +28,8 @@ #include "addnewtorrentdialog.h" +#include + #include #include #include @@ -231,7 +233,7 @@ int AddNewTorrentDialog::savePathHistoryLength() { const int defaultHistoryLength = 8; const int value = settings()->loadValue(KEY_SAVEPATHHISTORYLENGTH, defaultHistoryLength); - return qBound(minPathHistoryLength, value, maxPathHistoryLength); + return std::clamp(value, minPathHistoryLength, maxPathHistoryLength); } void AddNewTorrentDialog::setSavePathHistoryLength(const int value) diff --git a/src/gui/properties/downloadedpiecesbar.cpp b/src/gui/properties/downloadedpiecesbar.cpp index 12a69cd3b..322432120 100644 --- a/src/gui/properties/downloadedpiecesbar.cpp +++ b/src/gui/properties/downloadedpiecesbar.cpp @@ -28,6 +28,7 @@ #include "downloadedpiecesbar.h" +#include #include #include @@ -117,7 +118,7 @@ QVector DownloadedPiecesBar::bitfieldToFloatVector(const QBitArray &vecin value /= ratio; // float precision sometimes gives > 1, because it's not possible to store irrational numbers - value = qMin(value, 1.0f); + value = std::min(value, 1.0f); result[x] = value; } diff --git a/src/gui/properties/pieceavailabilitybar.cpp b/src/gui/properties/pieceavailabilitybar.cpp index 3eba18020..4156dfd1a 100644 --- a/src/gui/properties/pieceavailabilitybar.cpp +++ b/src/gui/properties/pieceavailabilitybar.cpp @@ -28,6 +28,7 @@ #include "pieceavailabilitybar.h" +#include #include #include @@ -46,9 +47,9 @@ QVector PieceAvailabilityBar::intToFloatVector(const QVector &vecin, const int maxElement = *std::max_element(vecin.begin(), vecin.end()); - // qMax because in normalization we don't want divide by 0 + // std::max because in normalization we don't want divide by 0 // if maxElement == 0 check will be disabled please enable this line: - // const int maxElement = qMax(*std::max_element(avail.begin(), avail.end()), 1); + // const int maxElement = std::max(*std::max_element(avail.begin(), avail.end()), 1); if (maxElement == 0) return result; @@ -115,7 +116,7 @@ QVector PieceAvailabilityBar::intToFloatVector(const QVector &vecin, value /= ratio * maxElement; // float precision sometimes gives > 1, because it's not possible to store irrational numbers - value = qMin(value, 1.0f); + value = std::min(value, 1.0f); result[x] = value; } diff --git a/src/gui/speedlimitdialog.cpp b/src/gui/speedlimitdialog.cpp index adae8f56c..93435a66b 100644 --- a/src/gui/speedlimitdialog.cpp +++ b/src/gui/speedlimitdialog.cpp @@ -28,6 +28,8 @@ #include "speedlimitdialog.h" +#include + #include #include "base/bittorrent/session.h" @@ -65,17 +67,17 @@ SpeedLimitDialog::SpeedLimitDialog(QWidget *parent) slider->setValue(value); }; const auto *session = BitTorrent::Session::instance(); - const int uploadVal = qMax(0, (session->globalUploadSpeedLimit() / 1024)); - const int downloadVal = qMax(0, (session->globalDownloadSpeedLimit() / 1024)); - const int maxUpload = qMax(10000, (session->globalUploadSpeedLimit() / 1024)); - const int maxDownload = qMax(10000, (session->globalDownloadSpeedLimit() / 1024)); + const int uploadVal = std::max(0, (session->globalUploadSpeedLimit() / 1024)); + const int downloadVal = std::max(0, (session->globalDownloadSpeedLimit() / 1024)); + const int maxUpload = std::max(10000, (session->globalUploadSpeedLimit() / 1024)); + const int maxDownload = std::max(10000, (session->globalDownloadSpeedLimit() / 1024)); initSlider(m_ui->sliderUploadLimit, uploadVal, maxUpload); initSlider(m_ui->sliderDownloadLimit, downloadVal, maxDownload); - const int altUploadVal = qMax(0, (session->altGlobalUploadSpeedLimit() / 1024)); - const int altDownloadVal = qMax(0, (session->altGlobalDownloadSpeedLimit() / 1024)); - const int altMaxUpload = qMax(10000, (session->altGlobalUploadSpeedLimit() / 1024)); - const int altMaxDownload = qMax(10000, (session->altGlobalDownloadSpeedLimit() / 1024)); + const int altUploadVal = std::max(0, (session->altGlobalUploadSpeedLimit() / 1024)); + const int altDownloadVal = std::max(0, (session->altGlobalDownloadSpeedLimit() / 1024)); + const int altMaxUpload = std::max(10000, (session->altGlobalUploadSpeedLimit() / 1024)); + const int altMaxDownload = std::max(10000, (session->altGlobalDownloadSpeedLimit() / 1024)); initSlider(m_ui->sliderAltUploadLimit, altUploadVal, altMaxUpload); initSlider(m_ui->sliderAltDownloadLimit, altDownloadVal, altMaxDownload); diff --git a/src/gui/torrentoptionsdialog.cpp b/src/gui/torrentoptionsdialog.cpp index b348e1a00..823ad1939 100644 --- a/src/gui/torrentoptionsdialog.cpp +++ b/src/gui/torrentoptionsdialog.cpp @@ -30,6 +30,8 @@ #include "torrentoptionsdialog.h" +#include + #include #include #include @@ -78,8 +80,8 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVectorsavePath(); const QString firstTorrentCategory = torrents[0]->category(); - const int firstTorrentUpLimit = qMax(0, torrents[0]->uploadLimit()); - const int firstTorrentDownLimit = qMax(0, torrents[0]->downloadLimit()); + const int firstTorrentUpLimit = std::max(0, torrents[0]->uploadLimit()); + const int firstTorrentDownLimit = std::max(0, torrents[0]->downloadLimit()); const qreal firstTorrentRatio = torrents[0]->ratioLimit(); const int firstTorrentSeedingTime = torrents[0]->seedingTimeLimit(); @@ -112,12 +114,12 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVectoruploadLimit()) != firstTorrentUpLimit) + if (std::max(0, torrent->uploadLimit()) != firstTorrentUpLimit) allSameUpLimit = false; } if (allSameDownLimit) { - if (qMax(0, torrent->downloadLimit()) != firstTorrentDownLimit) + if (std::max(0, torrent->downloadLimit()) != firstTorrentDownLimit) allSameDownLimit = false; } if (allSameRatio) @@ -201,8 +203,8 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVectoraltGlobalDownloadSpeedLimit() / 1024) : (session->globalDownloadSpeedLimit() / 1024); - const int uploadVal = qMax(0, (firstTorrentUpLimit / 1024)); - const int downloadVal = qMax(0, (firstTorrentDownLimit / 1024)); + const int uploadVal = std::max(0, (firstTorrentUpLimit / 1024)); + const int downloadVal = std::max(0, (firstTorrentDownLimit / 1024)); int maxUpload = (globalUploadLimit <= 0) ? 10000 : globalUploadLimit; int maxDownload = (globalDownloadLimit <= 0) ? 10000 : globalDownloadLimit;