mirror of
https://github.com/matrix-construct/construct
synced 2024-12-25 15:04:10 +01:00
ircd:Ⓜ️ Optimize various callsites for type queries.
This commit is contained in:
parent
31dfedbcd7
commit
f78e23149d
7 changed files with 17 additions and 17 deletions
|
@ -465,7 +465,7 @@ ircd::m::dbs::_index_event_refs_m_relates(db::txn &txn,
|
|||
if(!json::get<"content"_>(event).has("m.relates_to"))
|
||||
return;
|
||||
|
||||
if(json::type(json::get<"content"_>(event).get("m.relates_to")) != json::OBJECT)
|
||||
if(!json::type(json::get<"content"_>(event).get("m.relates_to"), json::OBJECT))
|
||||
return;
|
||||
|
||||
const json::object &m_relates_to
|
||||
|
@ -549,7 +549,7 @@ ircd::m::dbs::_index_event_refs_m_relates_m_reply(db::txn &txn,
|
|||
if(!json::get<"content"_>(event).has("m.relates_to"))
|
||||
return;
|
||||
|
||||
if(json::type(json::get<"content"_>(event).get("m.relates_to")) != json::OBJECT)
|
||||
if(!json::type(json::get<"content"_>(event).get("m.relates_to"), json::OBJECT))
|
||||
return;
|
||||
|
||||
const json::object &m_relates_to
|
||||
|
@ -560,7 +560,7 @@ ircd::m::dbs::_index_event_refs_m_relates_m_reply(db::txn &txn,
|
|||
if(!m_relates_to.has("m.in_reply_to"))
|
||||
return;
|
||||
|
||||
if(json::type(m_relates_to.get("m.in_reply_to")) != json::OBJECT)
|
||||
if(!json::type(m_relates_to.get("m.in_reply_to"), json::OBJECT))
|
||||
{
|
||||
log::derror
|
||||
{
|
||||
|
|
|
@ -218,7 +218,7 @@ ircd::m::get(std::nothrow_t,
|
|||
|
||||
// The user expects an unquoted string to their closure, the same as
|
||||
// if this value was found in its own column.
|
||||
if(json::type(value) == json::STRING)
|
||||
if(json::type(value, json::STRING))
|
||||
value = json::string(value);
|
||||
|
||||
ret = true;
|
||||
|
|
|
@ -146,11 +146,11 @@ try
|
|||
tokens(path, ".", token_view_bool{[&value]
|
||||
(const string_view &key)
|
||||
{
|
||||
if(json::type(value, std::nothrow) != json::OBJECT)
|
||||
if(!json::type(value, json::OBJECT))
|
||||
return false;
|
||||
|
||||
value = json::object(value)[key];
|
||||
if(likely(json::type(value, std::nothrow) != json::STRING))
|
||||
if(likely(!json::type(value, json::STRING)))
|
||||
return true;
|
||||
|
||||
value = json::string(value);
|
||||
|
@ -580,7 +580,7 @@ ircd::m::push::notifying(const rule &rule)
|
|||
|
||||
for(const string_view &action : actions)
|
||||
{
|
||||
if(json::type(action, std::nothrow) != json::STRING)
|
||||
if(!json::type(action, json::STRING))
|
||||
continue;
|
||||
|
||||
const json::string &string
|
||||
|
@ -608,7 +608,7 @@ ircd::m::push::highlighting(const rule &rule)
|
|||
|
||||
for(const string_view &action : actions)
|
||||
{
|
||||
if(json::type(action, std::nothrow) != json::OBJECT)
|
||||
if(!json::type(action, json::OBJECT))
|
||||
continue;
|
||||
|
||||
const json::object &object
|
||||
|
|
|
@ -569,7 +569,7 @@ const
|
|||
(const json::object &content)
|
||||
{
|
||||
for(const auto &[key, val] : content)
|
||||
ret += json::type(val) == json::OBJECT;
|
||||
ret += json::type(val, json::OBJECT);
|
||||
});
|
||||
|
||||
return ret;
|
||||
|
@ -659,7 +659,7 @@ const
|
|||
content.get(prop)
|
||||
};
|
||||
|
||||
ret = json::type(value) == json::OBJECT;
|
||||
ret = json::type(value, json::OBJECT);
|
||||
});
|
||||
|
||||
return ret;
|
||||
|
@ -694,7 +694,7 @@ const
|
|||
{
|
||||
for(const auto &[key, val] : content)
|
||||
{
|
||||
if(json::type(val) != json::OBJECT)
|
||||
if(!json::type(val, json::OBJECT))
|
||||
continue;
|
||||
|
||||
if(!closure(key, std::numeric_limits<int64_t>::min()))
|
||||
|
@ -733,7 +733,7 @@ const
|
|||
};
|
||||
|
||||
const string_view _collection{collection};
|
||||
if(prop && (!_collection || json::type(_collection) != json::OBJECT))
|
||||
if(prop && (!_collection || !json::type(_collection, json::OBJECT)))
|
||||
return;
|
||||
|
||||
for(auto it(begin(collection)); it != end(collection) && ret; ++it)
|
||||
|
|
|
@ -263,12 +263,12 @@ const
|
|||
content[prop]
|
||||
};
|
||||
|
||||
if(!list || json::type(list, std::nothrow) != json::ARRAY)
|
||||
if(!list || !json::type(list, json::ARRAY))
|
||||
return;
|
||||
|
||||
for(auto it(begin(list)); it != end(list) && ret; ++it)
|
||||
{
|
||||
if(json::type(*it, json::strict, std::nothrow) != json::STRING)
|
||||
if(!json::type(*it, json::STRING, json::strict))
|
||||
continue;
|
||||
|
||||
if(!closure(json::string(*it)))
|
||||
|
|
|
@ -72,7 +72,7 @@ try
|
|||
content["m.relates_to"]
|
||||
};
|
||||
|
||||
if(!m_relates_to || json::type(m_relates_to) != json::OBJECT)
|
||||
if(!m_relates_to || !json::type(m_relates_to, json::OBJECT))
|
||||
return;
|
||||
|
||||
const json::object &m_in_reply_to
|
||||
|
@ -82,7 +82,7 @@ try
|
|||
|
||||
const m::event::id &event_id
|
||||
{
|
||||
json::type(m_in_reply_to, std::nothrow) == json::OBJECT?
|
||||
json::type(m_in_reply_to, json::OBJECT)?
|
||||
m_in_reply_to.get<json::string>("event_id"):
|
||||
m_relates_to.get<json::string>("event_id")
|
||||
};
|
||||
|
|
|
@ -71,7 +71,7 @@ ircd::m::auth_room_power_levels(const m::event &event,
|
|||
// a. If users key in content is not a dictionary with keys that are
|
||||
// valid user IDs with values that are integers (or a string that is
|
||||
// an integer), reject.
|
||||
if(json::type(json::get<"content"_>(event).get("users")) != json::OBJECT)
|
||||
if(!json::type(json::get<"content"_>(event).get("users"), json::OBJECT))
|
||||
throw FAIL
|
||||
{
|
||||
"m.room.power_levels content.users is not a json object."
|
||||
|
|
Loading…
Reference in a new issue