From a81d399130931328dc7bdf787c667ad02b1b213a Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 24 Sep 2024 13:59:01 -0700 Subject: [PATCH] Avoid forward_as_tuple for comparing EAXVECTORs Some compilers don't seem to be able to optimize this properly, amd will put a list of addresses on the stack for each member of both operands, then load the value from each address individually to compare. It doesn't seem to realize what it's comparing to do it directly, creating a bloated. less efficient comparison that the compiler will give up on trying to inline. This at least prevents the inline failure warning, but the individual EAX effect structs still use it. C++20 should allow creating default comparison operators by auto-generating member-wise comparisons, so unless it's a performance bottleneck, it can be fixed later. --- al/eax/api.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/al/eax/api.h b/al/eax/api.h index 3e621d30..8ac1e62f 100644 --- a/al/eax/api.h +++ b/al/eax/api.h @@ -37,12 +37,14 @@ inline bool operator!=(const GUID& lhs, const GUID& rhs) noexcept { return !(lhs == rhs); } #endif // _WIN32 +/* TODO: This seems to create very inefficient comparisons. C++20 should allow + * creating default comparison operators, avoiding the need for this. + */ #define DECL_EQOP(T, ...) \ [[nodiscard]] auto get_members() const noexcept { return std::forward_as_tuple(__VA_ARGS__); } \ [[nodiscard]] friend bool operator==(const T &lhs, const T &rhs) noexcept \ -{ return lhs.get_members() == rhs.get_members(); } \ -[[nodiscard]] friend bool operator!=(const T &lhs, const T &rhs) noexcept \ -{ return !(lhs == rhs); } +{ return lhs.get_members() == rhs.get_members(); } \ +[[nodiscard]] friend bool operator!=(const T &lhs, const T &rhs) noexcept { return !(lhs == rhs); } extern const GUID DSPROPSETID_EAX_ReverbProperties; @@ -281,13 +283,11 @@ struct EAXVECTOR { float x; float y; float z; - [[nodiscard]] - auto get_members() const noexcept { return std::forward_as_tuple(x, y, z); } -}; // EAXVECTOR +}; [[nodiscard]] inline bool operator==(const EAXVECTOR& lhs, const EAXVECTOR& rhs) noexcept -{ return lhs.get_members() == rhs.get_members(); } +{ return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z; } [[nodiscard]] inline bool operator!=(const EAXVECTOR& lhs, const EAXVECTOR& rhs) noexcept -- 2.11.4.GIT