From 5361ad1617898651dd8e7f3523d495fcbde0a632 Mon Sep 17 00:00:00 2001 From: Jinny You Date: Mon, 13 Jan 2025 20:13:56 +0800 Subject: [PATCH] common: optimize clamp() for reduced overhead in web --- src/common/tvgMath.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common/tvgMath.h b/src/common/tvgMath.h index 9c269475..a3f7a61f 100644 --- a/src/common/tvgMath.h +++ b/src/common/tvgMath.h @@ -71,7 +71,9 @@ static inline bool equal(float a, float b) template static inline constexpr const T& clamp(const T& v, const T& min, const T& max) { - return std::min(std::max(v, min), max); + if (v < min) return min; + else if (v > max) return max; + return v; } /************************************************************************/