0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2025-01-13 08:23:56 +01:00

ircd::json: Minor reorg.

This commit is contained in:
Jason Volk 2020-07-06 07:02:51 -07:00
parent b32d2f07f5
commit b80b06135b

View file

@ -346,6 +346,46 @@ ircd::json::printer
}
const ircd::json::printer;
template<class gen,
class... attr>
[[gnu::always_inline]]
inline void
ircd::json::printer::operator()(mutable_buffer &out,
gen&& g,
attr&&... a)
const
{
++stats.print_calls;
const prof::scope_cycles timer{stats.print_cycles};
if(unlikely(!ircd::generate(out, std::forward<gen>(g), std::forward<attr>(a)...)))
throw print_error
{
"Failed to generate JSON"
};
}
template<class it_a,
class it_b,
class closure>
[[gnu::always_inline]]
inline void
ircd::json::printer::list_protocol(mutable_buffer &out,
it_a it,
const it_b &end,
closure&& lambda)
{
if(likely(it != end))
{
lambda(out, *it);
for(++it; it != end; ++it)
{
const auto &printer(json::printer);
printer(out, printer.value_sep);
lambda(out, *it);
}
}
}
inline void
ircd::json::printer::string_generate(unused_type,
string_context &g,
@ -388,46 +428,6 @@ noexcept
ret = !overflow;
}
template<class gen,
class... attr>
[[gnu::always_inline]]
inline void
ircd::json::printer::operator()(mutable_buffer &out,
gen&& g,
attr&&... a)
const
{
++stats.print_calls;
const prof::scope_cycles timer{stats.print_cycles};
if(unlikely(!ircd::generate(out, std::forward<gen>(g), std::forward<attr>(a)...)))
throw print_error
{
"Failed to generate JSON"
};
}
template<class it_a,
class it_b,
class closure>
[[gnu::always_inline]]
inline void
ircd::json::printer::list_protocol(mutable_buffer &out,
it_a it,
const it_b &end,
closure&& lambda)
{
if(likely(it != end))
{
lambda(out, *it);
for(++it; it != end; ++it)
{
const auto &printer(json::printer);
printer(out, printer.value_sep);
lambda(out, *it);
}
}
}
template<class gen,
class... attr>
[[gnu::always_inline]]