Add copy2() constexpr
This commit is contained in:
parent
4d1c6034eb
commit
8c5c428622
@ -1049,11 +1049,19 @@ inline auto equal2(const char* lhs, const char* rhs) -> bool {
|
||||
}
|
||||
|
||||
// Copies two characters from src to dst.
|
||||
template <typename Char> void copy2(Char* dst, const char* src) {
|
||||
*dst++ = static_cast<Char>(*src++);
|
||||
*dst = static_cast<Char>(*src);
|
||||
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_INLINE void copy2(char* dst, const char* src) { memcpy(dst, src, 2); }
|
||||
|
||||
template <typename Iterator> struct format_decimal_result {
|
||||
Iterator begin;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user