0

Migrate some uses of min/max to base::clamp

This is not a complete migration, but those instances for which min/max
were used in an obviously "clamp" way.

Bug: 1231569
Change-Id: Ib609d65139b0779eac2b987a5e08788816246eb2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3043206
Auto-Submit: Avi Drissman <avi@chromium.org>
Reviewed-by: Eugene Zemtsov <eugene@chromium.org>
Reviewed-by: Michael Spang <spang@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: David Tseng <dtseng@chromium.org>
Reviewed-by: Reilly Grant <reillyg@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#908233}
This commit is contained in:
Avi Drissman
2021-08-04 00:08:48 +00:00
committed by Chromium LUCI CQ
parent 91a0c5762f
commit e043dd252d
5 changed files with 15 additions and 11 deletions
content/browser/speech
device/gamepad
media/base
pdf/pdfium
ui/ozone/demo

@ -9,9 +9,8 @@
#include <wrl/client.h>
#include <wrl/implements.h>
#include <algorithm>
#include "base/bind.h"
#include "base/cxx17_backports.h"
#include "base/macros.h"
#include "base/no_destructor.h"
#include "base/sequenced_task_runner.h"
@ -276,7 +275,7 @@ void TtsPlatformImplBackgroundWorker::ProcessSpeech(
// value to an int before calling NumberToWString. TODO(dtseng): cleanup if
// we ever use any other properties that require xml.
double adjusted_pitch =
std::max<double>(-10, std::min<double>(params.pitch * 10 - 10, 10));
base::clamp<double>(params.pitch * 10 - 10, -10, 10);
std::wstring adjusted_pitch_string =
base::NumberToWString(static_cast<int>(adjusted_pitch));
prefix = L"<pitch absmiddle=\"" + adjusted_pitch_string + L"\">";

@ -18,6 +18,7 @@
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/check_op.h"
#include "base/cxx17_backports.h"
#include "base/location.h"
#include "base/mac/foundation_util.h"
#include "base/mac/scoped_ioobject.h"
@ -337,9 +338,8 @@ void XboxControllerMac::SetVibration(double strong_magnitude,
return;
// Clamp magnitudes to [0,1]
strong_magnitude =
std::max<double>(0.0, std::min<double>(strong_magnitude, 1.0));
weak_magnitude = std::max<double>(0.0, std::min<double>(weak_magnitude, 1.0));
strong_magnitude = base::clamp<double>(strong_magnitude, 0.0, 1.0);
weak_magnitude = base::clamp<double>(weak_magnitude, 0.0, 1.0);
if (xinput_type_ == kXInputTypeXbox360) {
WriteXbox360Rumble(static_cast<uint8_t>(strong_magnitude * 255.0),

@ -4,7 +4,10 @@
#include "media/base/video_decoder.h"
#include <algorithm>
#include "base/command_line.h"
#include "base/cxx17_backports.h"
#include "base/strings/string_number_conversions.h"
#include "base/system/sys_info.h"
#include "media/base/limits.h"
@ -56,9 +59,9 @@ int VideoDecoder::GetRecommendedThreadCount(int desired_threads) {
// zero threads; I.e., decoding will execute on the calling thread. Therefore,
// at least two threads are required to allow decoding to progress outside of
// each Decode() call.
return std::min(std::max(desired_threads,
static_cast<int>(limits::kMinVideoDecodeThreads)),
static_cast<int>(limits::kMaxVideoDecodeThreads));
return base::clamp(desired_threads,
static_cast<int>(limits::kMinVideoDecodeThreads),
static_cast<int>(limits::kMaxVideoDecodeThreads));
}
} // namespace media

@ -14,6 +14,7 @@
#include "base/bind.h"
#include "base/callback.h"
#include "base/check_op.h"
#include "base/cxx17_backports.h"
#include "base/metrics/histogram_functions.h"
#include "base/numerics/math_constants.h"
#include "base/numerics/safe_math.h"
@ -933,7 +934,7 @@ float PDFiumPage::PreProcessAndTransformInPageCoordX(float x) {
// If `x` < 0, scroll to the left side of the page.
// If `x` > page width, scroll to the right side of the page.
return TransformPageToScreenX(
std::max(std::min(x, FPDF_GetPageWidthF(GetPage())), 0.0f));
base::clamp(x, 0.0f, FPDF_GetPageWidthF(GetPage())));
}
float PDFiumPage::PreProcessAndTransformInPageCoordY(float y) {

@ -11,6 +11,7 @@
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/cxx17_backports.h"
#include "base/macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/trace_event/trace_event.h"
@ -174,7 +175,7 @@ bool SurfacelessGlRenderer::Initialize() {
base::StringToInt(
command_line->GetSwitchValueASCII("enable-overlay").c_str(),
&requested_overlay_cnt);
overlay_cnt_ = std::max(1, std::min(kMaxLayers, requested_overlay_cnt));
overlay_cnt_ = base::clamp(requested_overlay_cnt, 1, kMaxLayers);
const gfx::Size overlay_size =
gfx::Size(size_.width() / 8, size_.height() / 8);