summaryrefslogtreecommitdiff
path: root/src/libstddjb/uint64_reverse.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-10-18 16:13:24 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-10-18 16:13:24 +0000
commit45923c08b00ccdfd888caf6d2b555a137c563988 (patch)
tree5dc167cf4b8e3ff372f59ca9fb6ba0940387c83c /src/libstddjb/uint64_reverse.c
parent62a04cdd0b6811c07bbafae37fe906a36fa800b1 (diff)
downloadskalibs-45923c08b00ccdfd888caf6d2b555a137c563988.tar.xz
Better packing / unpacking code
Godbolted for x86_64 with gcc and clang.
Diffstat (limited to 'src/libstddjb/uint64_reverse.c')
-rw-r--r--src/libstddjb/uint64_reverse.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/libstddjb/uint64_reverse.c b/src/libstddjb/uint64_reverse.c
index 5a616f5..a870b31 100644
--- a/src/libstddjb/uint64_reverse.c
+++ b/src/libstddjb/uint64_reverse.c
@@ -1,15 +1,16 @@
/* ISC license. */
+#include <string.h>
#include <skalibs/uint64.h>
void uint64_reverse (char *s, size_t n)
{
while (n--)
{
- char c = s[0] ; s[0] = s[7] ; s[7] = c ;
- c = s[1] ; s[1] = s[6] ; s[6] = c ;
- c = s[2] ; s[2] = s[5] ; s[5] = c ;
- c = s[3] ; s[3] = s[4] ; s[4] = c ;
- s += 8 ;
+ uint64_t x ;
+ memcpy(&x, s, sizeof(uint64_t)) ;
+ x = uint64_bswap(x) ;
+ memcpy(s, &x, sizeof(uint64_t)) ;
+ s += sizeof(uint64_t) ;
}
}