mirror of
https://github.com/fmtlib/fmt.git
synced 2025-09-25 14:10:55 +02:00
Store size in a local variable while unchanged
This commit is contained in:
@@ -1844,15 +1844,17 @@ template <typename T> class buffer {
|
|||||||
void
|
void
|
||||||
append(const U* begin, const U* end) {
|
append(const U* begin, const U* end) {
|
||||||
while (begin != end) {
|
while (begin != end) {
|
||||||
auto free_cap = capacity_ - size_;
|
auto size = size_;
|
||||||
|
auto free_cap = capacity_ - size;
|
||||||
auto count = to_unsigned(end - begin);
|
auto count = to_unsigned(end - begin);
|
||||||
if (free_cap < count) {
|
if (free_cap < count) {
|
||||||
grow_(*this, size_ + count);
|
grow_(*this, size + count);
|
||||||
free_cap = capacity_ - size_;
|
size = size_;
|
||||||
count = (count < free_cap) ? count : free_cap;
|
free_cap = capacity_ - size;
|
||||||
|
count = count < free_cap ? count : free_cap;
|
||||||
}
|
}
|
||||||
// A loop is faster than memcpy on small sizes.
|
// A loop is faster than memcpy on small sizes.
|
||||||
T* out = ptr_ + size_;
|
T* out = ptr_ + size;
|
||||||
for (size_t i = 0; i < count; ++i) out[i] = begin[i];
|
for (size_t i = 0; i < count; ++i) out[i] = begin[i];
|
||||||
size_ += count;
|
size_ += count;
|
||||||
begin += count;
|
begin += count;
|
||||||
|
Reference in New Issue
Block a user