mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
AK: Use __builtin_bswap() in NetworkOrdered.
This commit is contained in:
parent
a2e5b821b4
commit
eb129bd730
Notes:
sideshowbarker
2024-07-19 13:28:58 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/eb129bd7300
1 changed files with 8 additions and 10 deletions
|
@ -3,18 +3,16 @@
|
|||
#include <AK/Types.h>
|
||||
|
||||
template<typename T>
|
||||
[[gnu::always_inline]] inline T convert_between_host_and_network(T host_value)
|
||||
[[gnu::always_inline]] inline T convert_between_host_and_network(T value)
|
||||
{
|
||||
if constexpr (sizeof(T) == 4) {
|
||||
auto* s = (byte*)&host_value;
|
||||
return (dword)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);
|
||||
}
|
||||
if constexpr (sizeof(T) == 2) {
|
||||
auto* s = (byte*)&host_value;
|
||||
return (word)(s[0] << 8 | s[1]);
|
||||
}
|
||||
if constexpr (sizeof(T) == 8)
|
||||
return __builtin_bswap64(value);
|
||||
if constexpr (sizeof(T) == 4)
|
||||
return __builtin_bswap32(value);
|
||||
if constexpr (sizeof(T) == 2)
|
||||
return __builtin_bswap16(value);
|
||||
if constexpr (sizeof(T) == 1)
|
||||
return host_value;
|
||||
return value;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
|
Loading…
Reference in a new issue