Skip to content

Commit

Permalink
Don't use memcpy in append
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jul 14, 2024
1 parent f97deb0 commit f29a7e7
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions include/fmt/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit f29a7e7

Please sign in to comment.