Browse Source

Use `std::clamp()` instead of various custom implementations

PR #19501.
adaptive-webui-19844
Victor Chernyakin 1 year ago committed by GitHub
parent
commit
e045b4678d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/app/application.cpp
  2. 6
      src/base/bittorrent/sessionimpl.cpp
  3. 3
      src/base/preferences.cpp

8
src/app/application.cpp

@ -427,12 +427,12 @@ void Application::setFileLoggerDeleteOld(const bool value) @@ -427,12 +427,12 @@ void Application::setFileLoggerDeleteOld(const bool value)
int Application::fileLoggerMaxSize() const
{
const int val = m_storeFileLoggerMaxSize.get(DEFAULT_FILELOG_SIZE);
return std::min(std::max(val, MIN_FILELOG_SIZE), MAX_FILELOG_SIZE);
return std::clamp(val, MIN_FILELOG_SIZE, MAX_FILELOG_SIZE);
}
void Application::setFileLoggerMaxSize(const int bytes)
{
const int clampedValue = std::min(std::max(bytes, MIN_FILELOG_SIZE), MAX_FILELOG_SIZE);
const int clampedValue = std::clamp(bytes, MIN_FILELOG_SIZE, MAX_FILELOG_SIZE);
if (m_fileLogger)
m_fileLogger->setMaxSize(clampedValue);
m_storeFileLoggerMaxSize = clampedValue;
@ -441,12 +441,12 @@ void Application::setFileLoggerMaxSize(const int bytes) @@ -441,12 +441,12 @@ void Application::setFileLoggerMaxSize(const int bytes)
int Application::fileLoggerAge() const
{
const int val = m_storeFileLoggerAge.get(1);
return std::min(std::max(val, 1), 365);
return std::clamp(val, 1, 365);
}
void Application::setFileLoggerAge(const int value)
{
m_storeFileLoggerAge = std::min(std::max(value, 1), 365);
m_storeFileLoggerAge = std::clamp(value, 1, 365);
}
int Application::fileLoggerAgeType() const

6
src/base/bittorrent/sessionimpl.cpp

@ -266,11 +266,7 @@ namespace @@ -266,11 +266,7 @@ namespace
{
return [lower, upper](const T value) -> T
{
if (value < lower)
return lower;
if (value > upper)
return upper;
return value;
return std::clamp(value, lower, upper);
};
}

3
src/base/preferences.cpp

@ -29,6 +29,7 @@ @@ -29,6 +29,7 @@
#include "preferences.h"
#include <algorithm>
#include <chrono>
#ifdef Q_OS_MACOS
@ -2122,7 +2123,7 @@ int Preferences::addNewTorrentDialogSavePathHistoryLength() const @@ -2122,7 +2123,7 @@ int Preferences::addNewTorrentDialogSavePathHistoryLength() const
void Preferences::setAddNewTorrentDialogSavePathHistoryLength(const int value)
{
const int clampedValue = qBound(0, value, 99);
const int clampedValue = std::clamp(value, 0, 99);
const int oldValue = addNewTorrentDialogSavePathHistoryLength();
if (clampedValue == oldValue)
return;

Loading…
Cancel
Save