Remove custom_formatter

This commit is contained in:
Victor Zverovich 2023-12-31 12:34:18 -08:00
parent 4aa24f54cd
commit a5bacf3fef
2 changed files with 12 additions and 16 deletions

View File

@ -1675,6 +1675,15 @@ template <typename Context> class basic_format_arg {
auto is_arithmetic() const -> bool { auto is_arithmetic() const -> bool {
return detail::is_arithmetic_type(type_); return detail::is_arithmetic_type(type_);
} }
FMT_INLINE auto format_custom(const char_type* parse_begin,
typename Context::parse_context_type& parse_ctx,
Context& ctx) -> bool {
if (type_ != detail::type::custom_type) return false;
parse_ctx.advance_to(parse_begin);
value_.custom.format(value_.custom.value, parse_ctx, ctx);
return true;
}
}; };
/** /**

View File

@ -3801,17 +3801,6 @@ template <typename Char> struct arg_formatter {
} }
}; };
template <typename Char> struct custom_formatter {
basic_format_parse_context<Char>& parse_ctx;
buffer_context<Char>& ctx;
void operator()(
typename basic_format_arg<buffer_context<Char>>::handle h) const {
h.format(parse_ctx, ctx);
}
template <typename T> void operator()(T) const {}
};
struct width_checker { struct width_checker {
template <typename T, FMT_ENABLE_IF(is_integer<T>::value)> template <typename T, FMT_ENABLE_IF(is_integer<T>::value)>
FMT_CONSTEXPR auto operator()(T value) -> unsigned long long { FMT_CONSTEXPR auto operator()(T value) -> unsigned long long {
@ -4408,11 +4397,9 @@ void vformat_to(buffer<Char>& buf, basic_string_view<Char> fmt,
auto on_format_specs(int id, const Char* begin, const Char* end) auto on_format_specs(int id, const Char* begin, const Char* end)
-> const Char* { -> const Char* {
auto arg = get_arg(context, id); auto arg = get_arg(context, id);
if (arg.type() == type::custom_type) { // Not using a visitor for custom types gives better codegen.
parse_context.advance_to(begin); if (arg.format_custom(begin, parse_context, context))
visit_format_arg(custom_formatter<Char>{parse_context, context}, arg);
return parse_context.begin(); return parse_context.begin();
}
auto specs = detail::dynamic_format_specs<Char>(); auto specs = detail::dynamic_format_specs<Char>();
begin = parse_format_specs(begin, end, specs, parse_context, arg.type()); begin = parse_format_specs(begin, end, specs, parse_context, arg.type());
detail::handle_dynamic_spec<detail::width_checker>( detail::handle_dynamic_spec<detail::width_checker>(
@ -4529,7 +4516,7 @@ formatter<T, Char,
} }
auto specs = specs_; auto specs = specs_;
detail::handle_dynamic_spec<detail::width_checker>(specs.width, detail::handle_dynamic_spec<detail::width_checker>(specs.width,
specs.width_ref, ctx); specs.width_ref, ctx);
detail::handle_dynamic_spec<detail::precision_checker>( detail::handle_dynamic_spec<detail::precision_checker>(
specs.precision, specs.precision_ref, ctx); specs.precision, specs.precision_ref, ctx);
return detail::write<Char>(ctx.out(), val, specs, ctx.locale()); return detail::write<Char>(ctx.out(), val, specs, ctx.locale());