Printf get container (#1982)

* eliminate one case where basic_print_context would copy a string into a fmt::basic_memory_buffer character by character instead of using fmt::basic_memory_buffer::append

* use detail::write instead of re-implementing it

* use to_unsigned to avoid signedness conversion warnings
This commit is contained in:
rimathia 2020-11-12 17:37:04 +01:00 committed by GitHub
parent 7abc3c01e0
commit 986fa00406
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -480,11 +480,13 @@ OutputIt basic_printf_context<OutputIt, Char>::format() {
} }
char_type c = *it++; char_type c = *it++;
if (it != end && *it == c) { if (it != end && *it == c) {
out = std::copy(start, it, out); out = detail::write(
out, basic_string_view<Char>(start, detail::to_unsigned(it - start)));
start = ++it; start = ++it;
continue; continue;
} }
out = std::copy(start, it - 1, out); out = detail::write(out, basic_string_view<Char>(
start, detail::to_unsigned(it - 1 - start)));
format_specs specs; format_specs specs;
specs.align = align::right; specs.align = align::right;
@ -596,7 +598,8 @@ OutputIt basic_printf_context<OutputIt, Char>::format() {
// Format argument. // Format argument.
out = visit_format_arg(ArgFormatter(out, specs, *this), arg); out = visit_format_arg(ArgFormatter(out, specs, *this), arg);
} }
return std::copy(start, it, out); return detail::write(
out, basic_string_view<Char>(start, detail::to_unsigned(it - start)));
} }
template <typename Char> template <typename Char>