From b95a7a8a9e9d17a56e3f3357e6da7bcc41b048f2 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 26 Aug 2019 11:00:14 -0700 Subject: [PATCH] ircd::exception: Add hide_name construction overload to macro. --- include/ircd/exception.h | 17 +++++++++++++++- ircd/json.cc | 44 +++++++++++++++++++++++----------------- 2 files changed, 41 insertions(+), 20 deletions(-) diff --git a/include/ircd/exception.h b/include/ircd/exception.h index ee5ee4c3d..74075dd98 100644 --- a/include/ircd/exception.h +++ b/include/ircd/exception.h @@ -89,9 +89,10 @@ struct ircd::exception 512UL }; - protected: IRCD_OVERLOAD(generate_skip) + IRCD_OVERLOAD(hide_name) + protected: char buf[BUFSIZE]; ssize_t generate(const char *const &name, const string_view &fmt, const va_rtti &ap) noexcept; @@ -156,6 +157,20 @@ struct name \ :parent \ { \ template \ + name(hide_name_t, const string_view &fmt, args&&... ap) noexcept \ + :parent{generate_skip} \ + { \ + generate(fmt, ircd::va_rtti{std::forward(ap)...}); \ + } \ + \ + template \ + name(hide_name_t, const string_view &fmt = " ") noexcept \ + :parent{generate_skip} \ + { \ + generate(fmt, ircd::va_rtti{}); \ + } \ + \ + template \ name(const string_view &fmt, args&&... ap) noexcept \ :parent{generate_skip} \ { \ diff --git a/ircd/json.cc b/ircd/json.cc index 0a2fd8200..f34a3eac7 100644 --- a/ircd/json.cc +++ b/ircd/json.cc @@ -1784,27 +1784,21 @@ ircd::string_view ircd::json::stringify(mutable_buffer &buf, const iov &iov) { - const ctx::critical_assertion ca; - thread_local const member *m[iov::max_size]; - if(unlikely(size_t(iov.size()) > iov.max_size)) - throw iov::oversize + static const auto addressof //TODO: XXX + { + [](const member &m) noexcept { - "IOV has %zd members but maximum is %zu", - iov.size(), - iov.max_size - }; + return std::addressof(m); + } + }; - std::transform(std::begin(iov), std::end(iov), m, [] - (const member &m) + static const auto less_member { - return &m; - }); - - std::sort(m, m + iov.size(), [] - (const member *const &a, const member *const &b) - { - return *a < *b; - }); + [](const member *const &a, const member *const &b) noexcept + { + return *a < *b; + } + }; static const auto print_member { @@ -1815,7 +1809,19 @@ ircd::json::stringify(mutable_buffer &buf, } }; - char *const start{begin(buf)}; + thread_local const member *m[iov::max_size]; + const ctx::critical_assertion ca; + if(unlikely(size_t(iov.size()) > iov.max_size)) + throw iov::oversize + { + "IOV has %zd members but maximum is %zu", + iov.size(), + iov.max_size + }; + + const auto start(begin(buf)); + std::transform(std::begin(iov), std::end(iov), m, addressof); + std::sort(m, m + iov.size(), less_member); printer(buf, printer.object_begin); printer::list_protocol(buf, m, m + iov.size(), print_member); printer(buf, printer.object_end);