refactor: Fix readability-use-std-min-max

This commit is contained in:
Lars Toenning
2025-10-25 15:49:22 +02:00
parent 369450107b
commit 8a877e85b7
15 changed files with 23 additions and 23 deletions

View File

@@ -42,7 +42,7 @@ Checks: >
modernize-use-transparent-functors,
modernize-use-uncaught-exceptions,
modernize-use-using,
readability-use-std-min-max,
CheckOptions:
- key: readability-identifier-naming.ClassCase

View File

@@ -173,7 +173,7 @@ namespace swift::core::afv::audio
double db = qBound(minDb, inputVolumeStreamArgs.PeakDB, maxDb);
double ratio = (db - minDb) / (maxDb - minDb);
if (ratio < 0.30) { ratio = 0.0; }
if (ratio > 1.0) { ratio = 1.0; }
ratio = std::min(ratio, 1.0);
inputVolumeStreamArgs.PeakVU = ratio;
emit inputVolumeStream(inputVolumeStreamArgs);
m_sampleCount = 0;

View File

@@ -51,7 +51,7 @@ namespace swift::core::afv::audio
for (float sample : std::as_const(buffer))
{
const float absSample = qAbs(sample);
if (absSample > m_maxSampleOutput) { m_maxSampleOutput = absSample; }
m_maxSampleOutput = std::max(absSample, m_maxSampleOutput);
}
m_sampleCount += buffer.size();
@@ -63,7 +63,7 @@ namespace swift::core::afv::audio
const double db = qBound(m_minDb, outputVolumeStreamArgs.PeakDb, m_maxDb);
double ratio = (db - m_minDb) / (m_maxDb - m_minDb);
if (ratio < 0.30) { ratio = 0.0; }
if (ratio > 1.0) { ratio = 1.0; }
ratio = std::min(ratio, 1.0);
outputVolumeStreamArgs.PeakVU = ratio;
emit outputVolumeStream(outputVolumeStreamArgs);
m_sampleCount = 0;

View File

@@ -1040,7 +1040,7 @@ namespace swift::core
if (!this->isUpdateAllRemoteAircraft(startTime)) { this->resetUpdateAllRemoteAircraft(); }
if (m_statsMaxUpdateTimeMs < dt) { m_statsMaxUpdateTimeMs = dt; }
m_statsMaxUpdateTimeMs = std::max(m_statsMaxUpdateTimeMs, dt);
if (m_statsLastUpdateAircraftRequestedMs > 0)
{
m_statsUpdateAircraftRequestedDeltaMs = startTime - m_statsLastUpdateAircraftRequestedMs;

View File

@@ -65,8 +65,7 @@ namespace swift::gui::components
void CDbAutoSimulatorStashingComponent::updateProgressIndicator(int percent)
{
if (percent > 100) { percent = 100; }
if (percent < 0) { percent = 0; }
percent = std::clamp(percent, 0, 100);
ui->pb_StashingProgress->setValue(percent);
}

View File

@@ -163,8 +163,7 @@ namespace swift::gui::components
void CDbAutoStashingComponent::updateProgressIndicator(int percent)
{
if (percent > 100) { percent = 100; }
if (percent < 0) { percent = 0; }
percent = std::clamp(percent, 0, 100);
ui->pb_StashingProgress->setValue(percent);
ui->le_Stashed->setText(QString::number(m_noStashed));
ui->le_NoData->setText(QString::number(m_noData));
@@ -249,7 +248,7 @@ namespace swift::gui::components
if (max < all)
{
int maxPercent = autoStashed.size() * 100 / max;
if (maxPercent > percent) { percent = maxPercent; }
percent = std::max(maxPercent, percent);
}
this->updateProgressIndicator(percent);
}

View File

@@ -403,7 +403,7 @@ namespace swift::gui::components
{
int v = ui->pb_LogoffTimeout->value();
v -= 1;
if (v < 0) { v = 0; }
v = std::max(v, 0);
ui->pb_LogoffTimeout->setValue(v);
if (v <= 0)
{

View File

@@ -150,7 +150,7 @@ namespace swift::gui::models
const int columns = columnCount();
const int rows = rowCount();
if (columns < 1) { return; }
if (startRowIndex < 0) { startRowIndex = 0; }
startRowIndex = std::max(startRowIndex, 0);
if (endRowIndex >= rows) { endRowIndex = rows - 1; }
const QModelIndex topLeft(createIndex(startRowIndex, 0));
const QModelIndex bottomRight(createIndex(endRowIndex, columns - 1));

View File

@@ -93,7 +93,7 @@ namespace swift::misc::network
for (const CUrlLog &rl : *this)
{
if (rl.isPending()) { continue; }
if (rl.getResponseTimeMs() > max) { max = rl.getResponseTimeMs(); }
max = std::max(rl.getResponseTimeMs(), max);
}
return max;
}
@@ -105,7 +105,7 @@ namespace swift::misc::network
for (const CUrlLog &rl : *this)
{
if (rl.isPending()) { continue; }
if (rl.getResponseTimeMs() < min) { min = rl.getResponseTimeMs(); }
min = std::min(rl.getResponseTimeMs(), min);
}
return min;
}

View File

@@ -63,7 +63,7 @@ namespace swift::misc::simulation::settings
int freqRgb, int privRgb, int servRgb, int statRgb, int supRgb)
{
if (topPx >= 0) { bottomPx = -1; }
if (lines < 3) { lines = 3; }
lines = std::max(lines, 3);
this->setMessageBoxValues(
std::to_string(leftPx) + ";" + std::to_string(topPx) + ";" + std::to_string(rightPx) + ";" +
std::to_string(bottomPx) + ";" + std::to_string(lines) + ";" + std::to_string(durationMs) + ";" +

View File

@@ -105,7 +105,7 @@ namespace swift::misc::simulation
const qint64 deltaMs = now - startedMs;
m_pendingElevationRequests.remove(requestedForCallsign);
m_statsCurrentElevRequestTimeMs = deltaMs;
if (m_statsMaxElevRequestTimeMs < deltaMs) { m_statsMaxElevRequestTimeMs = deltaMs; }
m_statsMaxElevRequestTimeMs = std::max(m_statsMaxElevRequestTimeMs, deltaMs);
}
}
return true;

View File

@@ -187,7 +187,7 @@ namespace swift::misc
if (msg.isEmpty()) { continue; }
newMsgs.append(msg.getMessage());
CStatusMessage::StatusSeverity ms = msg.getSeverity();
if (s < ms) { s = ms; }
s = std::max(s, ms);
cats.push_back(msg.getCategories());
}
const CStatusMessage newMsg(cats, s, newMsgs.join(", "));

View File

@@ -6,6 +6,8 @@
#ifndef SWIFT_MISC_TIMESTAMPOBJECTLIST_H
#define SWIFT_MISC_TIMESTAMPOBJECTLIST_H
#include <algorithm>
#include <QtGlobal>
#include "config/buildconfig.h"
@@ -382,8 +384,8 @@ namespace swift::misc
const ITimestampBased &l = last;
const ITimestampBased &o = object;
const qint64 diff = l.getAbsTimeDifferenceMs(o);
if (diff > mmm.max) { mmm.max = diff; }
if (diff < mmm.min) { mmm.min = diff; }
mmm.max = std::max(diff, mmm.max);
mmm.min = std::min(diff, mmm.min);
mean += diff;
}
c++;
@@ -722,8 +724,8 @@ namespace swift::misc
{
if (!object.hasNonZeroOffsetTime()) { continue; }
const qint64 os = object.getTimeOffsetMs();
if (os > mmm.max) { mmm.max = os; }
if (os < mmm.min) { mmm.min = os; }
mmm.max = std::max(os, mmm.max);
mmm.min = std::min(os, mmm.min);
mean += os;
c++;
}

View File

@@ -821,7 +821,7 @@ namespace swift::simplugin::flightgear
const qint64 wasStartedMs = m_addingInProgressAircraft.value(cs);
const qint64 deltaTimeMs = QDateTime::currentMSecsSinceEpoch() - wasStartedMs;
m_statsAddCurrentTimeMs = deltaTimeMs;
if (deltaTimeMs > m_statsAddMaxTimeMs) { m_statsAddMaxTimeMs = deltaTimeMs; }
m_statsAddMaxTimeMs = std::max(deltaTimeMs, m_statsAddMaxTimeMs);
m_addingInProgressAircraft.remove(cs);
}

View File

@@ -1171,7 +1171,7 @@ namespace swift::simplugin::xplane
const qint64 wasStartedMs = m_addingInProgressAircraft.value(cs);
const qint64 deltaTimeMs = QDateTime::currentMSecsSinceEpoch() - wasStartedMs;
m_statsAddCurrentTimeMs = deltaTimeMs;
if (deltaTimeMs > m_statsAddMaxTimeMs) { m_statsAddMaxTimeMs = deltaTimeMs; }
m_statsAddMaxTimeMs = std::max(deltaTimeMs, m_statsAddMaxTimeMs);
m_addingInProgressAircraft.remove(cs);
}