mirror of
https://github.com/fmtlib/fmt.git
synced 2025-03-23 13:20:46 +00:00
Don't use memcpy in append
This commit is contained in:
parent
f97deb0d7d
commit
f29a7e7970
@ -930,12 +930,9 @@ template <typename T> class buffer {
|
|||||||
try_reserve(size_ + count);
|
try_reserve(size_ + count);
|
||||||
auto free_cap = capacity_ - size_;
|
auto free_cap = capacity_ - size_;
|
||||||
if (free_cap < count) count = free_cap;
|
if (free_cap < count) count = free_cap;
|
||||||
if (std::is_same<T, U>::value) {
|
// A loop is faster than memcpy on small sizes.
|
||||||
memcpy(ptr_ + size_, begin, count * sizeof(T));
|
T* out = ptr_ + size_;
|
||||||
} else {
|
for (size_t i = 0; i < count; ++i) out[i] = begin[i];
|
||||||
T* out = ptr_ + size_;
|
|
||||||
for (size_t i = 0; i < count; ++i) out[i] = begin[i];
|
|
||||||
}
|
|
||||||
size_ += count;
|
size_ += count;
|
||||||
begin += count;
|
begin += count;
|
||||||
}
|
}
|
||||||
@ -1217,14 +1214,6 @@ FMT_CONSTEXPR auto copy(InputIt begin, InputIt end, OutputIt out) -> OutputIt {
|
|||||||
return out;
|
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>
|
template <typename T, typename V, typename OutputIt>
|
||||||
FMT_CONSTEXPR auto copy(basic_string_view<V> s, OutputIt out) -> OutputIt {
|
FMT_CONSTEXPR auto copy(basic_string_view<V> s, OutputIt out) -> OutputIt {
|
||||||
return copy<T>(s.begin(), s.end(), out);
|
return copy<T>(s.begin(), s.end(), out);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user