diff --git a/include/ircd/json/tool.h b/include/ircd/json/tool.h index 8218209d8..ff19ae945 100644 --- a/include/ircd/json/tool.h +++ b/include/ircd/json/tool.h @@ -29,6 +29,13 @@ namespace ircd::json strung replace(const object &, const member &); } +inline ircd::json::strung +ircd::json::replace(const object &s, + const json::member &m) +{ + return replace(s, json::members{m}); +} + inline ircd::json::strung ircd::json::insert(const object &s, const json::member &m) diff --git a/ircd/json.cc b/ircd/json.cc index 8b1b8158a..57f81ea8c 100644 --- a/ircd/json.cc +++ b/ircd/json.cc @@ -604,11 +604,11 @@ ircd::json::replace(const object &s, { [](const json::members &r, const object::member &m) { - return std::any_of(begin(r), end(r), [&m] - (const json::member &r) - { - return string_view{r.first} == m.first; - }); + for(const auto &[k, v] : r) + if(string_view{k} == m.first) + return true; + + return false; } }; @@ -634,30 +634,6 @@ ircd::json::replace(const object &s, }; } -ircd::json::strung -ircd::json::replace(const object &s, - const json::member &m_) -{ - if(unlikely(!empty(s) && type(s) != type::OBJECT)) - throw type_error - { - "Cannot replace member into JSON of type %s", - reflect(type(s)) - }; - - size_t mctr {0}; - auto &mb(member_buffer); - for(const object::member &m : object{s}) - if(m.first != string_view{m_.first}) - mb.at(mctr++) = member{m}; - - mb.at(mctr++) = m_; - return strung - { - mb.data(), mb.data() + mctr - }; -} - ircd::json::strung ircd::json::insert(const object &s, const json::members &m)