Browse Source

Replace min, max, clamp functions with std counterparts

adaptive-webui-19844
Chocobo1 3 years ago
parent
commit
63043b4927
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 16
      src/base/bittorrent/session.cpp
  2. 2
      src/base/bittorrent/torrentimpl.cpp
  3. 4
      src/gui/addnewtorrentdialog.cpp
  4. 3
      src/gui/properties/downloadedpiecesbar.cpp
  5. 7
      src/gui/properties/pieceavailabilitybar.cpp
  6. 18
      src/gui/speedlimitdialog.cpp
  7. 14
      src/gui/torrentoptionsdialog.cpp

16
src/base/bittorrent/session.cpp

@ -3171,7 +3171,7 @@ void Session::setPeerTurnoverInterval(const int val)
int Session::asyncIOThreads() const 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) void Session::setAsyncIOThreads(const int num)
@ -3185,7 +3185,7 @@ void Session::setAsyncIOThreads(const int num)
int Session::hashingThreads() const 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) void Session::setHashingThreads(const int num)
@ -3213,12 +3213,12 @@ void Session::setFilePoolSize(const int size)
int Session::checkingMemUsage() const int Session::checkingMemUsage() const
{ {
return qMax(1, m_checkingMemUsage.get()); return std::max(1, m_checkingMemUsage.get());
} }
void Session::setCheckingMemUsage(int size) void Session::setCheckingMemUsage(int size)
{ {
size = qMax(size, 1); size = std::max(size, 1);
if (size == m_checkingMemUsage) if (size == m_checkingMemUsage)
return; return;
@ -3230,21 +3230,21 @@ void Session::setCheckingMemUsage(int size)
int Session::diskCacheSize() const int Session::diskCacheSize() const
{ {
#ifdef QBT_APP_64BIT #ifdef QBT_APP_64BIT
return qMin(m_diskCacheSize.get(), 33554431); // 32768GiB return std::min(m_diskCacheSize.get(), 33554431); // 32768GiB
#else #else
// When build as 32bit binary, set the maximum at less than 2GB to prevent crashes // 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 // 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 #endif
} }
void Session::setDiskCacheSize(int size) void Session::setDiskCacheSize(int size)
{ {
#ifdef QBT_APP_64BIT #ifdef QBT_APP_64BIT
size = qMin(size, 33554431); // 32768GiB size = std::min(size, 33554431); // 32768GiB
#else #else
// allocate 1536MiB and leave 512MiB to the rest of program data in RAM // allocate 1536MiB and leave 512MiB to the rest of program data in RAM
size = qMin(size, 1536); size = std::min(size, 1536);
#endif #endif
if (size != m_diskCacheSize) if (size != m_diskCacheSize)
{ {

2
src/base/bittorrent/torrentimpl.cpp

@ -1063,7 +1063,7 @@ qlonglong TorrentImpl::eta() const
seedingTimeEta = 0; seedingTimeEta = 0;
} }
return qMin(ratioEta, seedingTimeEta); return std::min(ratioEta, seedingTimeEta);
} }
if (!speedAverage.download) return MAX_ETA; if (!speedAverage.download) return MAX_ETA;

4
src/gui/addnewtorrentdialog.cpp

@ -28,6 +28,8 @@
#include "addnewtorrentdialog.h" #include "addnewtorrentdialog.h"
#include <algorithm>
#include <QDebug> #include <QDebug>
#include <QDir> #include <QDir>
#include <QFileDialog> #include <QFileDialog>
@ -231,7 +233,7 @@ int AddNewTorrentDialog::savePathHistoryLength()
{ {
const int defaultHistoryLength = 8; const int defaultHistoryLength = 8;
const int value = settings()->loadValue(KEY_SAVEPATHHISTORYLENGTH, defaultHistoryLength); 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) void AddNewTorrentDialog::setSavePathHistoryLength(const int value)

3
src/gui/properties/downloadedpiecesbar.cpp

@ -28,6 +28,7 @@
#include "downloadedpiecesbar.h" #include "downloadedpiecesbar.h"
#include <algorithm>
#include <cmath> #include <cmath>
#include <QDebug> #include <QDebug>
@ -117,7 +118,7 @@ QVector<float> DownloadedPiecesBar::bitfieldToFloatVector(const QBitArray &vecin
value /= ratio; value /= ratio;
// float precision sometimes gives > 1, because it's not possible to store irrational numbers // 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; result[x] = value;
} }

7
src/gui/properties/pieceavailabilitybar.cpp

@ -28,6 +28,7 @@
#include "pieceavailabilitybar.h" #include "pieceavailabilitybar.h"
#include <algorithm>
#include <cmath> #include <cmath>
#include <QDebug> #include <QDebug>
@ -46,9 +47,9 @@ QVector<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &vecin,
const int maxElement = *std::max_element(vecin.begin(), vecin.end()); 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: // 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) if (maxElement == 0)
return result; return result;
@ -115,7 +116,7 @@ QVector<float> PieceAvailabilityBar::intToFloatVector(const QVector<int> &vecin,
value /= ratio * maxElement; value /= ratio * maxElement;
// float precision sometimes gives > 1, because it's not possible to store irrational numbers // 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; result[x] = value;
} }

18
src/gui/speedlimitdialog.cpp

@ -28,6 +28,8 @@
#include "speedlimitdialog.h" #include "speedlimitdialog.h"
#include <algorithm>
#include <QStyle> #include <QStyle>
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
@ -65,17 +67,17 @@ SpeedLimitDialog::SpeedLimitDialog(QWidget *parent)
slider->setValue(value); slider->setValue(value);
}; };
const auto *session = BitTorrent::Session::instance(); const auto *session = BitTorrent::Session::instance();
const int uploadVal = qMax(0, (session->globalUploadSpeedLimit() / 1024)); const int uploadVal = std::max(0, (session->globalUploadSpeedLimit() / 1024));
const int downloadVal = qMax(0, (session->globalDownloadSpeedLimit() / 1024)); const int downloadVal = std::max(0, (session->globalDownloadSpeedLimit() / 1024));
const int maxUpload = qMax(10000, (session->globalUploadSpeedLimit() / 1024)); const int maxUpload = std::max(10000, (session->globalUploadSpeedLimit() / 1024));
const int maxDownload = qMax(10000, (session->globalDownloadSpeedLimit() / 1024)); const int maxDownload = std::max(10000, (session->globalDownloadSpeedLimit() / 1024));
initSlider(m_ui->sliderUploadLimit, uploadVal, maxUpload); initSlider(m_ui->sliderUploadLimit, uploadVal, maxUpload);
initSlider(m_ui->sliderDownloadLimit, downloadVal, maxDownload); initSlider(m_ui->sliderDownloadLimit, downloadVal, maxDownload);
const int altUploadVal = qMax(0, (session->altGlobalUploadSpeedLimit() / 1024)); const int altUploadVal = std::max(0, (session->altGlobalUploadSpeedLimit() / 1024));
const int altDownloadVal = qMax(0, (session->altGlobalDownloadSpeedLimit() / 1024)); const int altDownloadVal = std::max(0, (session->altGlobalDownloadSpeedLimit() / 1024));
const int altMaxUpload = qMax(10000, (session->altGlobalUploadSpeedLimit() / 1024)); const int altMaxUpload = std::max(10000, (session->altGlobalUploadSpeedLimit() / 1024));
const int altMaxDownload = qMax(10000, (session->altGlobalDownloadSpeedLimit() / 1024)); const int altMaxDownload = std::max(10000, (session->altGlobalDownloadSpeedLimit() / 1024));
initSlider(m_ui->sliderAltUploadLimit, altUploadVal, altMaxUpload); initSlider(m_ui->sliderAltUploadLimit, altUploadVal, altMaxUpload);
initSlider(m_ui->sliderAltDownloadLimit, altDownloadVal, altMaxDownload); initSlider(m_ui->sliderAltDownloadLimit, altDownloadVal, altMaxDownload);

14
src/gui/torrentoptionsdialog.cpp

@ -30,6 +30,8 @@
#include "torrentoptionsdialog.h" #include "torrentoptionsdialog.h"
#include <algorithm>
#include <QLineEdit> #include <QLineEdit>
#include <QMessageBox> #include <QMessageBox>
#include <QString> #include <QString>
@ -78,8 +80,8 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
const QString firstTorrentSavePath = torrents[0]->savePath(); const QString firstTorrentSavePath = torrents[0]->savePath();
const QString firstTorrentCategory = torrents[0]->category(); const QString firstTorrentCategory = torrents[0]->category();
const int firstTorrentUpLimit = qMax(0, torrents[0]->uploadLimit()); const int firstTorrentUpLimit = std::max(0, torrents[0]->uploadLimit());
const int firstTorrentDownLimit = qMax(0, torrents[0]->downloadLimit()); const int firstTorrentDownLimit = std::max(0, torrents[0]->downloadLimit());
const qreal firstTorrentRatio = torrents[0]->ratioLimit(); const qreal firstTorrentRatio = torrents[0]->ratioLimit();
const int firstTorrentSeedingTime = torrents[0]->seedingTimeLimit(); const int firstTorrentSeedingTime = torrents[0]->seedingTimeLimit();
@ -112,12 +114,12 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
} }
if (allSameUpLimit) if (allSameUpLimit)
{ {
if (qMax(0, torrent->uploadLimit()) != firstTorrentUpLimit) if (std::max(0, torrent->uploadLimit()) != firstTorrentUpLimit)
allSameUpLimit = false; allSameUpLimit = false;
} }
if (allSameDownLimit) if (allSameDownLimit)
{ {
if (qMax(0, torrent->downloadLimit()) != firstTorrentDownLimit) if (std::max(0, torrent->downloadLimit()) != firstTorrentDownLimit)
allSameDownLimit = false; allSameDownLimit = false;
} }
if (allSameRatio) if (allSameRatio)
@ -201,8 +203,8 @@ TorrentOptionsDialog::TorrentOptionsDialog(QWidget *parent, const QVector<BitTor
? (session->altGlobalDownloadSpeedLimit() / 1024) ? (session->altGlobalDownloadSpeedLimit() / 1024)
: (session->globalDownloadSpeedLimit() / 1024); : (session->globalDownloadSpeedLimit() / 1024);
const int uploadVal = qMax(0, (firstTorrentUpLimit / 1024)); const int uploadVal = std::max(0, (firstTorrentUpLimit / 1024));
const int downloadVal = qMax(0, (firstTorrentDownLimit / 1024)); const int downloadVal = std::max(0, (firstTorrentDownLimit / 1024));
int maxUpload = (globalUploadLimit <= 0) ? 10000 : globalUploadLimit; int maxUpload = (globalUploadLimit <= 0) ? 10000 : globalUploadLimit;
int maxDownload = (globalDownloadLimit <= 0) ? 10000 : globalDownloadLimit; int maxDownload = (globalDownloadLimit <= 0) ? 10000 : globalDownloadLimit;

Loading…
Cancel
Save