From 87c5cd46acf4c503c936e202eac9f6503504e4d7 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Wed, 10 Mar 2021 07:04:04 -0800 Subject: [PATCH] Optimize parsing of argument ids --- include/fmt/format.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index ed55709c..b9cc7ea0 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -121,8 +121,8 @@ FMT_END_NAMESPACE # define FMT_THROW(x) throw x # endif # else -# define FMT_THROW(x) \ - do { \ +# define FMT_THROW(x) \ + do { \ FMT_ASSERT(false, (x).what()); \ } while (false) # endif @@ -2847,14 +2847,10 @@ class dynamic_specs_handler }; template -FMT_CONSTEXPR const Char* parse_arg_id(const Char* begin, const Char* end, - IDHandler&& handler) { +FMT_CONSTEXPR const Char* do_parse_arg_id(const Char* begin, const Char* end, + IDHandler&& handler) { FMT_ASSERT(begin != end, ""); Char c = *begin; - if (c == '}' || c == ':') { - handler(); - return begin; - } if (c >= '0' && c <= '9') { int index = 0; if (c != '0') @@ -2879,6 +2875,16 @@ FMT_CONSTEXPR const Char* parse_arg_id(const Char* begin, const Char* end, return it; } +template +FMT_CONSTEXPR_DECL FMT_INLINE const Char* parse_arg_id(const Char* begin, + const Char* end, + IDHandler&& handler) { + Char c = *begin; + if (c != '}' && c != ':') return do_parse_arg_id(begin, end, handler); + handler(); + return begin; +} + // Adapts SpecHandler to IDHandler API for dynamic width. template struct width_adapter { explicit FMT_CONSTEXPR width_adapter(SpecHandler& h) : handler(h) {}