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 3f0d1b0
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 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

0 comments on commit 3f0d1b0

Please sign in to comment.