From 5724d2d4c73de8035e28cd69544fe2ee6fa5e375 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 29 Apr 2021 00:13:12 +0300 Subject: [PATCH] Simplify umax Add operator less and conversion operator. --- Utilities/Config.cpp | 2 +- Utilities/bin_patch.cpp | 2 +- Utilities/cfmt.h | 8 +++----- rpcs3/util/types.hpp | 26 ++++++-------------------- 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/Utilities/Config.cpp b/Utilities/Config.cpp index 0ef1b882e3..d7d0198324 100644 --- a/Utilities/Config.cpp +++ b/Utilities/Config.cpp @@ -138,7 +138,7 @@ bool cfg::try_to_uint64(u64* out, const std::string& value, u64 min, u64 max) bool cfg::try_to_enum_value(u64* out, decltype(&fmt_class_string::format) func, const std::string& value) { - u64 max = -1; + u64 max = umax; for (u64 i = 0;; i++) { diff --git a/Utilities/bin_patch.cpp b/Utilities/bin_patch.cpp index a16f72324a..7a4c17f4b1 100644 --- a/Utilities/bin_patch.cpp +++ b/Utilities/bin_patch.cpp @@ -530,7 +530,7 @@ static std::basic_string apply_modification(const patch_engine::patch_info& auto ptr = dst + offset; - u32 resval = -1; + u32 resval = umax; switch (p.type) { diff --git a/Utilities/cfmt.h b/Utilities/cfmt.h index 3141ff6641..6b452fc317 100644 --- a/Utilities/cfmt.h +++ b/Utilities/cfmt.h @@ -7,8 +7,6 @@ #include #include "util/asm.hpp" -static const usz size_dropped = -1; - /* C-style format parser. Appends formatted string to `out`, returns number of characters written. `out`: mutable reference to std::string, std::vector or other compatible container @@ -43,7 +41,7 @@ usz cfmt_append(Dst& out, const Char* fmt, Src&& src) const auto drop_sequence = [&] { out.insert(out.end(), fmt - ctx.size, fmt); - ctx.size = size_dropped; + ctx.size = umax; }; const auto read_decimal = [&](uint result) -> uint @@ -143,7 +141,7 @@ usz cfmt_append(Dst& out, const Char* fmt, Src&& src) ctx = {0}; out.push_back(ch); } - else if (ctx.size == size_dropped) + else if (ctx.size == umax) { out.push_back(ch); } @@ -694,7 +692,7 @@ usz cfmt_append(Dst& out, const Char* fmt, Src&& src) } // Handle unfinished sequence - if (ctx.size && ctx.size != size_dropped) + if (ctx.size && ctx.size != umax) { fmt--, drop_sequence(); } diff --git a/rpcs3/util/types.hpp b/rpcs3/util/types.hpp index 35a26f8a2e..50e4b4e65b 100644 --- a/rpcs3/util/types.hpp +++ b/rpcs3/util/types.hpp @@ -480,39 +480,25 @@ struct get_int_impl<16> }; // Return magic value for any unsigned type -constexpr inline struct umax_helper +constexpr struct umax_impl_t { - constexpr umax_helper() noexcept = default; - template requires (std::is_unsigned_v>) || (std::is_same_v, u128>) - friend constexpr bool operator==(const umax_helper&, const T& rhs) + constexpr bool operator==(const T& rhs) const { return rhs == static_cast>(-1); } -#if __cpp_impl_three_way_comparison >= 201711 && !__INTELLISENSE__ -#else template requires (std::is_unsigned_v>) || (std::is_same_v, u128>) - friend constexpr bool operator==(const T& lhs, const umax_helper&) + constexpr bool operator<(const T& rhs) const { - return lhs == static_cast>(-1); - } -#endif - -#if __cpp_impl_three_way_comparison >= 201711 -#else - template requires (std::is_unsigned_v>) || (std::is_same_v, u128>) - friend constexpr bool operator!=(const umax_helper&, const T& rhs) - { - return rhs != static_cast>(-1); + return rhs < static_cast>(-1); } template requires (std::is_unsigned_v>) || (std::is_same_v, u128>) - friend constexpr bool operator!=(const T& lhs, const umax_helper&) + constexpr operator T() const { - return lhs != static_cast>(-1); + return static_cast>(-1); } -#endif } umax; enum class f16 : u16{};