Use memcpy in more cases in copy2

This commit is contained in:
Victor Zverovich 2021-09-12 12:23:45 -07:00
parent e47e99bb09
commit 04e3a79f76

View File

@ -1050,17 +1050,13 @@ inline auto equal2(const char* lhs, const char* rhs) -> bool {
// Copies two characters from src to dst.
template <typename Char>
FMT_CONSTEXPR20 FMT_INLINE void copy2(Char* dst, const char* src) {
if (!is_constant_evaluated() && std::is_same<Char, char>::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<Char>(dc0);
*dst = static_cast<Char>(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<Char>(*src++);
*dst = static_cast<Char>(*src);
}
template <typename Iterator> struct format_decimal_result {