Replace min, max, clamp functions with std counterparts

This commit is contained in:
Chocobo1 2021-12-27 20:31:57 +08:00
parent 3ea4c66d41
commit 63043b4927
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
7 changed files with 36 additions and 28 deletions

View file

@ -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)
{

View file

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

View file

@ -28,6 +28,8 @@
#include "addnewtorrentdialog.h"
#include <algorithm>
#include <QDebug>
#include <QDir>
#include <QFileDialog>
@ -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)

View file

@ -28,6 +28,7 @@
#include "downloadedpiecesbar.h"
#include <algorithm>
#include <cmath>
#include <QDebug>
@ -117,7 +118,7 @@ QVector<float> 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;
}

View file

@ -28,6 +28,7 @@
#include "pieceavailabilitybar.h"
#include <algorithm>
#include <cmath>
#include <QDebug>
@ -46,9 +47,9 @@ QVector<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &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<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &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;
}

View file

@ -28,6 +28,8 @@
#include "speedlimitdialog.h"
#include <algorithm>
#include <QStyle>
#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);

View file

@ -30,6 +30,8 @@
#include "torrentoptionsdialog.h"
#include <algorithm>
#include <QLineEdit>
#include <QMessageBox>
#include <QString>
@ -78,8 +80,8 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
const QString firstTorrentSavePath = torrents[0]->savePath();
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 QVector<BitTor
}
if (allSameUpLimit)
{
if (qMax(0, torrent->uploadLimit()) != 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 QVector<BitTor
? (session->altGlobalDownloadSpeedLimit() / 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;