aboutsummaryrefslogtreecommitdiffstats
path: root/al
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2022-02-13 23:53:00 -0800
committerChris Robinson <[email protected]>2022-02-13 23:53:00 -0800
commitf915b86dbb8a3d75e37a2813df093694aae0dcbb (patch)
treebd7054eb3bcbb1532a1888620f350fe3d5febe34 /al
parent98de566bc81427d0a37b574aa931cec33852a28f (diff)
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).
Diffstat (limited to 'al')
-rw-r--r--al/eax_api.h24
1 files 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 <cfloat>
#include <cstdint>
+#include <cstring>
#include <array>
@@ -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);
}