From 8efb5c30ce6e22b2f4f7b6b05435226eaa587b0e Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sat, 20 May 2023 17:36:14 +0800 Subject: [PATCH] counters: move fmt::formatter::format() to .cc to reduce the size of header file, in hope to speed the compilation. let's implement the implementation of format() function into .cc file. Refs #13245 Signed-off-by: Kefu Chai Closes #14010 --- counters.cc | 12 ++++++++++++ counters.hh | 12 ++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/counters.cc b/counters.cc index bc6e48ad44..a42b7415ef 100644 --- a/counters.cc +++ b/counters.cc @@ -12,6 +12,18 @@ #include +auto fmt::formatter::format(const counter_shard_view& csv, + fmt::format_context& ctx) const -> decltype(ctx.out()) { + return fmt::format_to(ctx.out(), "{{global_shard id: {} value: {}, clock: {}}}", + csv.id(), csv.value(), csv.logical_clock()); +} + +auto fmt::formatter::format(const counter_cell_view& ccv, + fmt::format_context& ctx) const -> decltype(ctx.out()) { + return fmt::format_to(ctx.out(), "{{counter_cell timestamp: {} shards: {{{}}}}}", + ccv.timestamp(), fmt::join(ccv.shards(), ", ")); +} + void counter_cell_builder::do_sort_and_remove_duplicates() { boost::range::sort(_shards, [] (auto& a, auto& b) { return a.id() < b.id(); }); diff --git a/counters.hh b/counters.hh index e492259a69..f07eb6e835 100644 --- a/counters.hh +++ b/counters.hh @@ -90,11 +90,7 @@ using counter_shard_view = basic_counter_shard_view; template <> struct fmt::formatter : fmt::formatter { - template - auto format(const counter_shard_view& csv, FormatContext& ctx) const { - return fmt::format_to(ctx.out(), "{{global_shard id: {} value: {}, clock: {}}}", - csv.id(), csv.value(), csv.logical_clock()); - } + auto format(const counter_shard_view&, fmt::format_context& ctx) const -> decltype(ctx.out()); }; class counter_shard { @@ -357,11 +353,7 @@ struct counter_cell_view : basic_counter_cell_view { template <> struct fmt::formatter : fmt::formatter { - template - auto format(const counter_cell_view& ccv, FormatContext& ctx) const { - return fmt::format_to(ctx.out(), "{{counter_cell timestamp: {} shards: {{{}}}}}", - ccv.timestamp(), fmt::join(ccv.shards(), ", ")); - } + auto format(const counter_cell_view&, fmt::format_context& ctx) const -> decltype(ctx.out()); }; struct counter_cell_mutable_view : basic_counter_cell_view {