Optimize default formatting

This commit is contained in:
Victor Zverovich
2018-09-12 07:34:22 -07:00
parent c8a8464f7d
commit 7110b46076
5 changed files with 58 additions and 44 deletions

View File

@@ -19,14 +19,15 @@ class custom_arg_formatter :
typedef fmt::back_insert_range<fmt::internal::buffer> range;
typedef fmt::arg_formatter<range> base;
custom_arg_formatter(fmt::format_context &ctx, fmt::format_specs &s)
custom_arg_formatter(
fmt::format_context &ctx, fmt::format_specs *s = FMT_NULL)
: base(ctx, s) {}
using base::operator();
iterator operator()(double value) {
// Comparing a float to 0.0 is safe
if (round(value * pow(10, spec().precision())) == 0.0)
if (round(value * pow(10, spec()->precision())) == 0.0)
value = 0;
return base::operator()(value);
}

View File

@@ -1471,7 +1471,7 @@ class mock_arg_formatter:
typedef fmt::internal::arg_formatter_base<buffer_range> base;
typedef buffer_range range;
mock_arg_formatter(fmt::format_context &ctx, fmt::format_specs &s)
mock_arg_formatter(fmt::format_context &ctx, fmt::format_specs *s = FMT_NULL)
: base(fmt::internal::get_container(ctx.out()), s) {
EXPECT_CALL(*this, call(42));
}

View File

@@ -50,7 +50,7 @@ typedef fmt::back_insert_range<fmt::internal::buffer> range;
struct test_arg_formatter: fmt::arg_formatter<range> {
test_arg_formatter(fmt::format_context &ctx, fmt::format_specs &s)
: fmt::arg_formatter<range>(ctx, s) {}
: fmt::arg_formatter<range>(ctx, &s) {}
};
TEST(OStreamTest, CustomArg) {