From c60fc0ccdd59bb68e88d70593dfcf05e07f0a393 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 1 Jul 2022 12:02:55 -0700 Subject: [PATCH] ircd::util: Improve bswap template codegen. --- include/ircd/util/bswap.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/include/ircd/util/bswap.h b/include/ircd/util/bswap.h index 74d4819f0..677d769f1 100644 --- a/include/ircd/util/bswap.h +++ b/include/ircd/util/bswap.h @@ -138,11 +138,18 @@ ircd::util::bswap(T *const val) noexcept { assert(val != nullptr); - const auto ptr + const auto &src { - reinterpret_cast(val) + reinterpret_cast(val) }; - std::reverse(ptr, ptr + sizeof(T)); + T tmp; + const auto &dst + { + reinterpret_cast(&tmp) + }; + + std::reverse_copy(src, src + sizeof(T), dst); + *val = tmp; return *val; }