Don't use memcpy in append

This commit is contained in:
Victor Zverovich 2024-07-14 12:40:21 -07:00
parent f97deb0d7d
commit f29a7e7970

View File

@ -930,12 +930,9 @@ template <typename T> class buffer {
try_reserve(size_ + count);
auto free_cap = capacity_ - size_;
if (free_cap < count) count = free_cap;
if (std::is_same<T, U>::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 <typename T>
FMT_CONSTEXPR auto copy(const T* begin, const T* end, T* out) -> T* {
if (is_constant_evaluated()) return copy<T, const T*, T*>(begin, end, out);
auto size = to_unsigned(end - begin);
if (size > 0) memcpy(out, begin, size * sizeof(T));
return out + size;
}
template <typename T, typename V, typename OutputIt>
FMT_CONSTEXPR auto copy(basic_string_view<V> s, OutputIt out) -> OutputIt {
return copy<T>(s.begin(), s.end(), out);