Apply minor optimization

This commit is contained in:
Victor Zverovich 2024-07-14 09:10:16 -07:00
parent 5ef93a9f80
commit 3541353512

View File

@ -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* { template <typename T> auto to_pointer(basic_appender<T> it, size_t n) -> T* {
buffer<T>& buf = get_container(it); buffer<T>& buf = get_container(it);
auto size = buf.size(); auto size = buf.size();
buf.try_reserve(size + n);
if (buf.capacity() < size + n) return nullptr; if (buf.capacity() < size + n) return nullptr;
buf.try_resize(size + n); buf.try_resize(size + n);
return buf.data() + size; return buf.data() + size;
@ -2317,15 +2318,13 @@ FMT_CONSTEXPR auto write(OutputIt out, T value) -> OutputIt {
if (negative) abs_value = ~abs_value + 1; if (negative) abs_value = ~abs_value + 1;
int num_digits = count_digits(abs_value); int num_digits = count_digits(abs_value);
auto size = (negative ? 1 : 0) + static_cast<size_t>(num_digits); auto size = (negative ? 1 : 0) + static_cast<size_t>(num_digits);
auto it = reserve(out, size); if (auto ptr = to_pointer<Char>(out, size)) {
if (auto ptr = to_pointer<Char>(it, size)) {
if (negative) *ptr++ = static_cast<Char>('-'); if (negative) *ptr++ = static_cast<Char>('-');
format_decimal<Char>(ptr, abs_value, num_digits); format_decimal<Char>(ptr, abs_value, num_digits);
return out; return out;
} }
if (negative) *it++ = static_cast<Char>('-'); if (negative) *out++ = static_cast<Char>('-');
it = format_decimal<Char>(it, abs_value, num_digits).end; return format_decimal<Char>(out, abs_value, num_digits).end;
return base_iterator(out, it);
} }
// DEPRECATED! // DEPRECATED!