mirror of
https://github.com/fmtlib/fmt.git
synced 2025-09-25 06:00:55 +02:00
Perf: Optimize function append in include/fmt/base.h (#4541)
This commit is contained in:
@@ -1844,10 +1844,13 @@ template <typename T> class buffer {
|
||||
void
|
||||
append(const U* begin, const U* end) {
|
||||
while (begin != end) {
|
||||
auto count = to_unsigned(end - begin);
|
||||
try_reserve(size_ + count);
|
||||
auto free_cap = capacity_ - size_;
|
||||
if (free_cap < count) count = free_cap;
|
||||
auto count = to_unsigned(end - begin);
|
||||
if (free_cap < count) {
|
||||
grow_(*this, size_ + count);
|
||||
free_cap = capacity_ - size_;
|
||||
count = (count < free_cap) ? count : free_cap;
|
||||
}
|
||||
// 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];
|
||||
|
Reference in New Issue
Block a user