mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 00:02:34 +01:00
ircd::json: Reduce replace() overloads to single linked procedure.
This commit is contained in:
parent
22b9cf515c
commit
dc13381822
2 changed files with 12 additions and 29 deletions
|
@ -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)
|
||||
|
|
34
ircd/json.cc
34
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)
|
||||
|
|
Loading…
Reference in a new issue