diff options
author | Sven Gothel <[email protected]> | 2022-04-10 02:10:13 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-04-10 02:10:13 +0200 |
commit | 54644844036a5eeaf3830ad327ad8a2ba197a4dd (patch) | |
tree | b07e09de3e10e7c4d524c0cf1f2aa546b075ef9d /include/jau/byte_util.hpp | |
parent | 5b99373aa46930b6749bf6e3dc48d13e4b30682c (diff) |
byte_util.hpp: Add manual optimization to generic bswap on uint8_t src -> dest
Diffstat (limited to 'include/jau/byte_util.hpp')
-rw-r--r-- | include/jau/byte_util.hpp | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/include/jau/byte_util.hpp b/include/jau/byte_util.hpp index e8b4e53..9805747 100644 --- a/include/jau/byte_util.hpp +++ b/include/jau/byte_util.hpp @@ -63,6 +63,8 @@ namespace jau { #define __has_builtin_bswap64 1 #endif + // Remember: constexpr specifier used in a function or static data member (since C++17) declaration implies inline. + constexpr uint16_t bswap(uint16_t const source) noexcept { #if defined __has_builtin_bswap16 return __builtin_bswap16(source); @@ -98,9 +100,10 @@ namespace jau { #endif } - constexpr void bswap(uint8_t * const sink, uint8_t const * const source, nsize_t const len) { - for(nsize_t i=0; i < len; ++i) { - sink[i] = source[len-1-i]; + constexpr void bswap(uint8_t * sink, uint8_t const * source, nsize_t len) { + source += len - 1; + for (; len > 0; len--) { + *sink++ = *source--; } } |