From 2fe5f1528fc134ced8c8f2e0a5d5ec3b9f2a44f4 Mon Sep 17 00:00:00 2001 From: Jesse Buhagiar Date: Sat, 21 Aug 2021 15:08:06 +1000 Subject: [PATCH] AK: Use `__builtin_bit_cast` if available We now use the compiler's buitin version of bitcast if it's available instead of just resorting to using the builtin `memcpy`. --- AK/BitCast.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AK/BitCast.h b/AK/BitCast.h index bed0f9d981e..bb3c28f4141 100644 --- a/AK/BitCast.h +++ b/AK/BitCast.h @@ -11,11 +11,15 @@ namespace AK { template inline T bit_cast(const U& a) { +#if (__has_builtin(__builtin_bit_cast)) + return __builtin_bit_cast(T, a); +#else static_assert(sizeof(T) == sizeof(U)); T result; __builtin_memcpy(&result, &a, sizeof(T)); return result; +#endif } }