Commit fe00cddd authored by Victor Zverovich's avatar Victor Zverovich

Move part counter to the namespace scope

to reduce the number of instantiations
parent 1a7d172d
...@@ -260,37 +260,24 @@ class prepared_format { ...@@ -260,37 +260,24 @@ class prepared_format {
PreparedPartsProvider parts_provider_; PreparedPartsProvider parts_provider_;
}; };
template <typename Format> class compiletime_prepared_parts_type_provider { template <typename Char> struct part_counter {
private:
using char_type = char_t<Format>;
class count_handler {
public: public:
FMT_CONSTEXPR count_handler() : counter_(0u) {} FMT_CONSTEXPR part_counter() : counter_(0u) {}
FMT_CONSTEXPR void on_text(const char_type* begin, const char_type* end) { FMT_CONSTEXPR void on_text(const Char* begin, const Char* end) {
if (begin != end) ++counter_; if (begin != end) ++counter_;
} }
FMT_CONSTEXPR void on_arg_id() { ++counter_; } FMT_CONSTEXPR void on_arg_id() { ++counter_; }
FMT_CONSTEXPR void on_arg_id(unsigned) { ++counter_; } FMT_CONSTEXPR void on_arg_id(unsigned) { ++counter_; }
FMT_CONSTEXPR void on_arg_id(basic_string_view<char_type>) { ++counter_; } FMT_CONSTEXPR void on_arg_id(basic_string_view<Char>) { ++counter_; }
FMT_CONSTEXPR void on_replacement_field(const char_type*) {}
FMT_CONSTEXPR const char_type* on_format_specs(const char_type* begin, FMT_CONSTEXPR void on_replacement_field(const Char*) {}
const char_type* end) {
return find_matching_brace(begin, end);
}
FMT_CONSTEXPR void on_error(const char*) {}
FMT_CONSTEXPR unsigned result() const { return counter_; } FMT_CONSTEXPR const Char* on_format_specs(const Char* begin,
const Char* end) {
private: // Find the matching brace.
FMT_CONSTEXPR const char_type* find_matching_brace(const char_type* begin, unsigned braces_counter = 0;
const char_type* end) {
unsigned braces_counter{0u};
for (; begin != end; ++begin) { for (; begin != end; ++begin) {
if (*begin == '{') { if (*begin == '{') {
++braces_counter; ++braces_counter;
...@@ -302,15 +289,23 @@ template <typename Format> class compiletime_prepared_parts_type_provider { ...@@ -302,15 +289,23 @@ template <typename Format> class compiletime_prepared_parts_type_provider {
return begin; return begin;
} }
FMT_CONSTEXPR void on_error(const char*) {}
FMT_CONSTEXPR unsigned result() const { return counter_; }
private: private:
unsigned counter_; unsigned counter_;
}; };
template <typename Format> class compiletime_prepared_parts_type_provider {
private:
using char_type = char_t<Format>;
static FMT_CONSTEXPR unsigned count_parts() { static FMT_CONSTEXPR unsigned count_parts() {
FMT_CONSTEXPR_DECL const auto text = to_string_view(Format{}); FMT_CONSTEXPR_DECL const auto text = to_string_view(Format{});
count_handler handler; part_counter<char_type> counter;
internal::parse_format_string</*IS_CONSTEXPR=*/true>(text, handler); internal::parse_format_string</*IS_CONSTEXPR=*/true>(text, counter);
return handler.result(); return counter.result();
} }
// Workaround for old compilers. Compiletime parts preparation will not be // Workaround for old compilers. Compiletime parts preparation will not be
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment