From 61e9bd018f1e04f03b5d75cb627816613043ed9f Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 26 Jan 2018 10:27:24 -0800 Subject: [PATCH] ircd::json: Eliminate unnecessary print() overload. --- include/ircd/json/json.h | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/include/ircd/json/json.h b/include/ircd/json/json.h index ea667ec68..151236cc4 100644 --- a/include/ircd/json/json.h +++ b/include/ircd/json/json.h @@ -65,7 +65,6 @@ namespace ircd::json /// eventually all lead to the stringify() friend function of the argument /// you pass to the template. template string_view stringify(const mutable_buffer &&mb, T&&... t); - template size_t print(char *const &buf, const size_t &max, T&&... t); template size_t print(const mutable_buffer &buf, T&&... t); template struct buffer; struct strung; @@ -158,33 +157,15 @@ size_t ircd::json::print(const mutable_buffer &buf, T&&... t) { - return print(data(buf), size(buf), std::forward(t)...); -} - -/// -/// Convenience template using the syntax print(buf, sizeof(buf), ...) -/// which stringifies with null termination into buffer. -/// -template -size_t -ircd::json::print(char *const &buf, - const size_t &max, - T&&... t) -{ - if(unlikely(!max)) + if(unlikely(!size(buf))) return 0; - mutable_buffer mb - { - buf, max - 1 - }; - const auto sv { - stringify(mb, std::forward(t)...) + stringify(mutable_buffer{buf}, std::forward(t)...) }; - assert(sv.size() < max); + assert(sv.size() < size(buf)); assert(valid(sv, std::nothrow)); //note: false alarm when T=json::member buf[sv.size()] = '\0'; return sv.size(); @@ -204,7 +185,7 @@ ircd::json::strung::strung(T&&... t) const auto max{ret.size() + 1}; const auto printed { - print(buf, max, std::forward(t)...) + print(mutable_buffer{buf, max}, std::forward(t)...) }; if(unlikely(printed != ret.size()))