diff --git a/rpcs3/Emu/Cell/SPUCommonRecompiler.cpp b/rpcs3/Emu/Cell/SPUCommonRecompiler.cpp index 2baaa15705..105b794862 100644 --- a/rpcs3/Emu/Cell/SPUCommonRecompiler.cpp +++ b/rpcs3/Emu/Cell/SPUCommonRecompiler.cpp @@ -37,21 +37,31 @@ constexpr u32 s_reg_max = spu_recompiler_base::s_reg_max; template struct span_less { - static int compare(const std::span& this_, const std::span& that) noexcept + static int compare(const std::span& lhs, const std::span& rhs) noexcept { - int res = std::memcmp(this_.data(), that.data(), std::min(this_.size_bytes(), that.size_bytes())); - - if (res == 0 && this_.size() != that.size()) + // TODO: Replace with std::lexicographical_compare_three_way when it becomes available to all compilers + for (usz i = 0, last = std::min(lhs.size(), rhs.size()); i != last; i++) { - res = this_.size() < that.size() ? -1 : 1; + const T vl = lhs[i]; + const T vr = rhs[i]; + + if (vl != vr) + { + return vl < vr ? -1 : 1; + } } - return res; + if (lhs.size() != rhs.size()) + { + return lhs.size() < rhs.size() ? -1 : 1; + } + + return 0; } - bool operator()(const std::span& this_, const std::span& that) const noexcept + bool operator()(const std::span& lhs, const std::span& rhs) const noexcept { - return compare(this_, that) < 0; + return compare(lhs, rhs) < 0; } };