Skip to content

Commit

Permalink
Use memcpy in more cases in copy2
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Sep 12, 2021
1 parent e47e99b commit 04e3a79
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 04e3a79

Please sign in to comment.