From 04e3a79f762aa28bb43a5d58e95ed168389f0c7e Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 12 Sep 2021 12:23:45 -0700 Subject: [PATCH] Use memcpy in more cases in copy2 --- include/fmt/format.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 2621cf84..c94fbece 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1050,17 +1050,13 @@ inline auto equal2(const char* lhs, const char* rhs) -> bool { // Copies two characters from src to dst. template -FMT_CONSTEXPR20 FMT_INLINE void copy2(Char* dst, const char* src) { - if (!is_constant_evaluated() && std::is_same::value) { - memcpy(dst, src, 2); - } else { - // We read both bytes before writing so that the compiler can do it in - // one pair of read/write instructions (even if Char aliases char) - char dc0 = *src++; - char dc1 = *src; - *dst++ = static_cast(dc0); - *dst = static_cast(dc1); +FMT_CONSTEXPR20 FMT_INLINE void copy2(Char* dst, const char* src) { + if (!is_constant_evaluated() && sizeof(Char) == sizeof(char)) { + memcpy(dst, src, 2); + return; } + *dst++ = static_cast(*src++); + *dst = static_cast(*src); } template struct format_decimal_result {