summaryrefslogtreecommitdiff
path: root/AK/NetworkOrdered.h
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-06-26 20:01:48 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-06-26 20:01:48 +0200
commiteb129bd7300383f73a25ea677c1d2deb90d9a55e (patch)
treed48eea6372aa60846dd347a3f05a98a2224ac734 /AK/NetworkOrdered.h
parenta2e5b821b45c54d77208d1a34c3cd0abc126b75a (diff)
downloadserenity-eb129bd7300383f73a25ea677c1d2deb90d9a55e.zip
AK: Use __builtin_bswap() in NetworkOrdered.
Diffstat (limited to 'AK/NetworkOrdered.h')
-rw-r--r--AK/NetworkOrdered.h18
1 files changed, 8 insertions, 10 deletions
diff --git a/AK/NetworkOrdered.h b/AK/NetworkOrdered.h
index ad657007e8..1f50e7be1f 100644
--- a/AK/NetworkOrdered.h
+++ b/AK/NetworkOrdered.h
@@ -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>