Optimize parsing of argument ids

This commit is contained in:
Victor Zverovich 2021-03-10 07:04:04 -08:00
parent 6a9016ea60
commit 87c5cd46ac

View File

@ -121,8 +121,8 @@ FMT_END_NAMESPACE
# define FMT_THROW(x) throw x # define FMT_THROW(x) throw x
# endif # endif
# else # else
# define FMT_THROW(x) \ # define FMT_THROW(x) \
do { \ do { \
FMT_ASSERT(false, (x).what()); \ FMT_ASSERT(false, (x).what()); \
} while (false) } while (false)
# endif # endif
@ -2847,14 +2847,10 @@ class dynamic_specs_handler
}; };
template <typename Char, typename IDHandler> template <typename Char, typename IDHandler>
FMT_CONSTEXPR const Char* parse_arg_id(const Char* begin, const Char* end, FMT_CONSTEXPR const Char* do_parse_arg_id(const Char* begin, const Char* end,
IDHandler&& handler) { IDHandler&& handler) {
FMT_ASSERT(begin != end, ""); FMT_ASSERT(begin != end, "");
Char c = *begin; Char c = *begin;
if (c == '}' || c == ':') {
handler();
return begin;
}
if (c >= '0' && c <= '9') { if (c >= '0' && c <= '9') {
int index = 0; int index = 0;
if (c != '0') if (c != '0')
@ -2879,6 +2875,16 @@ FMT_CONSTEXPR const Char* parse_arg_id(const Char* begin, const Char* end,
return it; return it;
} }
template <typename Char, typename IDHandler>
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. // Adapts SpecHandler to IDHandler API for dynamic width.
template <typename SpecHandler, typename Char> struct width_adapter { template <typename SpecHandler, typename Char> struct width_adapter {
explicit FMT_CONSTEXPR width_adapter(SpecHandler& h) : handler(h) {} explicit FMT_CONSTEXPR width_adapter(SpecHandler& h) : handler(h) {}