mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-19 11:14:41 +00:00
Apply minor optimization
This commit is contained in:
parent
5ef93a9f80
commit
3541353512
@ -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;
|
||||
@ -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!
|
||||
|
Loading…
Reference in New Issue
Block a user