mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-06 08:10:02 +00:00
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`.
This commit is contained in:
parent
4ab8939670
commit
2fe5f1528f
Notes:
sideshowbarker
2024-07-18 05:26:35 +09:00
Author: https://github.com/Quaker762
Commit: 2fe5f1528f
Pull-request: https://github.com/SerenityOS/serenity/pull/9527
Reviewed-by: https://github.com/Hendiadyoin1
Reviewed-by: https://github.com/alimpfard
1 changed files with 4 additions and 0 deletions
|
@ -11,11 +11,15 @@ namespace AK {
|
||||||
template<typename T, typename U>
|
template<typename T, typename U>
|
||||||
inline T bit_cast(const U& a)
|
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));
|
static_assert(sizeof(T) == sizeof(U));
|
||||||
|
|
||||||
T result;
|
T result;
|
||||||
__builtin_memcpy(&result, &a, sizeof(T));
|
__builtin_memcpy(&result, &a, sizeof(T));
|
||||||
return result;
|
return result;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue