From f29a7e7970349eec2c76f3c0eda3d5accdd3aa6b Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 14 Jul 2024 12:40:21 -0700 Subject: [PATCH] Don't use memcpy in append --- include/fmt/base.h | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/include/fmt/base.h b/include/fmt/base.h index 4d6a33bc..a2a05d40 100644 --- a/include/fmt/base.h +++ b/include/fmt/base.h @@ -930,12 +930,9 @@ template class buffer { try_reserve(size_ + count); auto free_cap = capacity_ - size_; if (free_cap < count) count = free_cap; - if (std::is_same::value) { - memcpy(ptr_ + size_, begin, count * sizeof(T)); - } else { - T* out = ptr_ + size_; - for (size_t i = 0; i < count; ++i) out[i] = begin[i]; - } + // A loop is faster than memcpy on small sizes. + T* out = ptr_ + size_; + for (size_t i = 0; i < count; ++i) out[i] = begin[i]; size_ += count; begin += count; } @@ -1217,14 +1214,6 @@ FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt { return out; } -template -FMT_CONSTEXPR auto copy(const T* begin, const T* end, T* out) -> T* { - if (is_constant_evaluated()) return copy(begin, end, out); - auto size = to_unsigned(end - begin); - if (size > 0) memcpy(out, begin, size * sizeof(T)); - return out + size; -} - template FMT_CONSTEXPR auto copy(basic_string_view s, OutputIt out) -> OutputIt { return copy(s.begin(), s.end(), out);