Skip to content

Commit

Permalink
Apply minor optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jul 14, 2024
1 parent 5ef93a9 commit 3541353
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ constexpr auto to_pointer(OutputIt, size_t) -> T* {
template <typename T> auto to_pointer(basic_appender<T> it, size_t n) -> T* {
buffer<T>& buf = get_container(it);
auto size = buf.size();
buf.try_reserve(size + n);
if (buf.capacity() < size + n) return nullptr;
buf.try_resize(size + n);
return buf.data() + size;
Expand Down Expand Up @@ -2317,15 +2318,13 @@ FMT_CONSTEXPR auto write(OutputIt out, T value) -> OutputIt {
if (negative) abs_value = ~abs_value + 1;
int num_digits = count_digits(abs_value);
auto size = (negative ? 1 : 0) + static_cast<size_t>(num_digits);
auto it = reserve(out, size);
if (auto ptr = to_pointer<Char>(it, size)) {
if (auto ptr = to_pointer<Char>(out, size)) {
if (negative) *ptr++ = static_cast<Char>('-');
format_decimal<Char>(ptr, abs_value, num_digits);
return out;
}
if (negative) *it++ = static_cast<Char>('-');
it = format_decimal<Char>(it, abs_value, num_digits).end;
return base_iterator(out, it);
if (negative) *out++ = static_cast<Char>('-');
return format_decimal<Char>(out, abs_value, num_digits).end;
}

// DEPRECATED!
Expand Down

0 comments on commit 3541353

Please sign in to comment.