From f915b86dbb8a3d75e37a2813df093694aae0dcbb Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 13 Feb 2022 23:53:00 -0800 Subject: Use memcmp to compare GUIDs Clang at least optimizes the old version horribly, doing each individual check (with short-circuiting) as written. In comparison, this memcmp gets inlined using only a few SIMD instructions (on capable targets). --- al/eax_api.h | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/al/eax_api.h b/al/eax_api.h index 7e506921..c5004ec6 100644 --- a/al/eax_api.h +++ b/al/eax_api.h @@ -12,6 +12,7 @@ #include #include +#include #include @@ -28,27 +29,12 @@ typedef struct _GUID std::uint8_t Data4[8]; } GUID; -inline constexpr bool operator==( - const GUID& lhs, - const GUID& rhs) noexcept -{ - return - lhs.Data1 == rhs.Data1 && - lhs.Data2 == rhs.Data2 && - lhs.Data3 == rhs.Data3 && - lhs.Data4[0] == rhs.Data4[0] && - lhs.Data4[1] == rhs.Data4[1] && - lhs.Data4[2] == rhs.Data4[2] && - lhs.Data4[3] == rhs.Data4[3] && - lhs.Data4[4] == rhs.Data4[4] && - lhs.Data4[5] == rhs.Data4[5] && - lhs.Data4[6] == rhs.Data4[6] && - lhs.Data4[7] == rhs.Data4[7]; +inline bool operator==(const GUID& lhs, const GUID& rhs) noexcept +{ + return std::memcmp(&lhs, &rhs, sizeof(GUID)) == 0; } -inline constexpr bool operator!=( - const GUID& lhs, - const GUID& rhs) noexcept +inline bool operator!=(const GUID& lhs, const GUID& rhs) noexcept { return !(lhs == rhs); } -- cgit v1.2.3