mirror of
https://github.com/matrix-construct/construct
synced 2024-11-25 16:22:35 +01:00
ircd:Ⓜ️:state: Eliminate remaining test-protocol iterations.
This commit is contained in:
parent
209aa550b3
commit
0b0d20884d
4 changed files with 48 additions and 49 deletions
|
@ -73,12 +73,11 @@ namespace ircd::m::state
|
|||
size_t count(const id &root, const string_view &type);
|
||||
size_t count(const id &root);
|
||||
|
||||
bool test(const id &root, const iter_bool_closure &);
|
||||
bool test(const id &root, const string_view &type, const iter_bool_closure &);
|
||||
bool test(const id &root, const string_view &type, const string_view &state_key_lb, const iter_bool_closure &);
|
||||
|
||||
bool for_each(const id &root, const iter_bool_closure &);
|
||||
void for_each(const id &root, const iter_closure &);
|
||||
bool for_each(const id &root, const string_view &type, const iter_bool_closure &);
|
||||
void for_each(const id &root, const string_view &type, const iter_closure &);
|
||||
bool for_each(const id &root, const string_view &type, const string_view &state_key_lb, const iter_bool_closure &);
|
||||
|
||||
size_t accumulate(const id &root, const iter_bool_closure &);
|
||||
|
||||
|
|
|
@ -1162,11 +1162,11 @@ ircd::m::room::state::for_each(const event::id::closure_bool &closure)
|
|||
const
|
||||
{
|
||||
if(!present())
|
||||
return !m::state::test(root_id, [&closure]
|
||||
return m::state::for_each(root_id, m::state::iter_bool_closure{[&closure]
|
||||
(const json::array &key, const string_view &event_id)
|
||||
{
|
||||
return !closure(unquote(event_id));
|
||||
});
|
||||
return closure(unquote(event_id));
|
||||
}});
|
||||
|
||||
return for_each(event::closure_idx_bool{[&closure]
|
||||
(const event::idx &idx)
|
||||
|
@ -1199,11 +1199,11 @@ ircd::m::room::state::for_each(const event::closure_idx_bool &closure)
|
|||
const
|
||||
{
|
||||
if(!present())
|
||||
return !m::state::test(root_id, [&closure]
|
||||
return m::state::for_each(root_id, m::state::iter_bool_closure{[&closure]
|
||||
(const json::array &key, const string_view &event_id)
|
||||
{
|
||||
return !closure(index(unquote(event_id), std::nothrow));
|
||||
});
|
||||
return closure(index(unquote(event_id), std::nothrow));
|
||||
}});
|
||||
|
||||
db::gopts opts
|
||||
{
|
||||
|
@ -1319,10 +1319,10 @@ ircd::m::room::state::for_each(const string_view &type,
|
|||
const
|
||||
{
|
||||
if(!present())
|
||||
return !m::state::test(root_id, type, state_key_lb, [&closure]
|
||||
return m::state::for_each(root_id, type, state_key_lb, [&closure]
|
||||
(const json::array &key, const string_view &event_id)
|
||||
{
|
||||
return !closure(unquote(event_id));
|
||||
return closure(unquote(event_id));
|
||||
});
|
||||
|
||||
return for_each(type, state_key_lb, event::closure_idx_bool{[&closure]
|
||||
|
@ -1346,10 +1346,10 @@ ircd::m::room::state::for_each(const string_view &type,
|
|||
const
|
||||
{
|
||||
if(!present())
|
||||
return !m::state::test(root_id, type, state_key_lb, [&closure]
|
||||
return m::state::for_each(root_id, type, state_key_lb, [&closure]
|
||||
(const json::array &key, const string_view &event_id)
|
||||
{
|
||||
return !closure(index(unquote(event_id), std::nothrow));
|
||||
return closure(index(unquote(event_id), std::nothrow));
|
||||
});
|
||||
|
||||
char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE];
|
||||
|
@ -1406,11 +1406,11 @@ ircd::m::room::state::for_each(const string_view &type,
|
|||
const
|
||||
{
|
||||
if(!present())
|
||||
return !m::state::test(root_id, type, state_key_lb, [&closure]
|
||||
return m::state::for_each(root_id, type, state_key_lb, [&closure]
|
||||
(const json::array &key, const string_view &event_id)
|
||||
{
|
||||
assert(size(key) >= 2);
|
||||
return !closure(unquote(key.at(1)));
|
||||
return closure(unquote(key.at(1)));
|
||||
});
|
||||
|
||||
char keybuf[dbs::ROOM_STATE_KEY_MAX_SIZE];
|
||||
|
@ -1466,7 +1466,7 @@ const
|
|||
char lastbuf[256]; //TODO: type maxlen
|
||||
if(!present())
|
||||
{
|
||||
m::state::for_each(root_id, [&closure, &last, &lastbuf]
|
||||
m::state::for_each(root_id, m::state::iter_bool_closure{[&closure, &last, &lastbuf]
|
||||
(const json::array &key, const string_view &)
|
||||
{
|
||||
assert(size(key) >= 2);
|
||||
|
@ -1480,7 +1480,7 @@ const
|
|||
|
||||
last = strlcpy(lastbuf, type);
|
||||
return closure(type);
|
||||
});
|
||||
}});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -112,11 +112,22 @@ void
|
|||
ircd::m::state::for_each(const string_view &root,
|
||||
const iter_closure &closure)
|
||||
{
|
||||
test(root, [&closure]
|
||||
for_each(root, iter_bool_closure{[&closure]
|
||||
(const json::array &key, const string_view &val)
|
||||
{
|
||||
closure(key, val);
|
||||
return false;
|
||||
return true;
|
||||
}});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::state::for_each(const string_view &root,
|
||||
const iter_bool_closure &closure)
|
||||
{
|
||||
return !dfs(root, [&closure]
|
||||
(const json::array &key, const string_view &val, const uint &, const uint &)
|
||||
{
|
||||
return !closure(key, val);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -125,29 +136,18 @@ ircd::m::state::for_each(const string_view &root,
|
|||
const string_view &type,
|
||||
const iter_closure &closure)
|
||||
{
|
||||
test(root, type, [&closure]
|
||||
for_each(root, type, iter_bool_closure{[&closure]
|
||||
(const json::array &key, const string_view &val)
|
||||
{
|
||||
closure(key, val);
|
||||
return false;
|
||||
});
|
||||
return true;
|
||||
}});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::state::test(const string_view &root,
|
||||
const iter_bool_closure &closure)
|
||||
{
|
||||
return dfs(root, [&closure]
|
||||
(const json::array &key, const string_view &val, const uint &, const uint &)
|
||||
{
|
||||
return closure(key, val);
|
||||
});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::state::test(const string_view &root,
|
||||
const string_view &type,
|
||||
const iter_bool_closure &closure)
|
||||
ircd::m::state::for_each(const string_view &root,
|
||||
const string_view &type,
|
||||
const iter_bool_closure &closure)
|
||||
{
|
||||
char buf[KEY_MAX_SZ];
|
||||
const json::array key
|
||||
|
@ -155,18 +155,18 @@ ircd::m::state::test(const string_view &root,
|
|||
make_key(buf, type)
|
||||
};
|
||||
|
||||
return dfs(root, key, [&closure]
|
||||
return !dfs(root, key, [&closure]
|
||||
(const json::array &key, const string_view &val, const uint &, const uint &)
|
||||
{
|
||||
return closure(key, val);
|
||||
return !closure(key, val);
|
||||
});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::state::test(const string_view &root,
|
||||
const string_view &type,
|
||||
const string_view &state_key_lb,
|
||||
const iter_bool_closure &closure)
|
||||
ircd::m::state::for_each(const string_view &root,
|
||||
const string_view &type,
|
||||
const string_view &state_key_lb,
|
||||
const iter_bool_closure &closure)
|
||||
{
|
||||
char buf[KEY_MAX_SZ];
|
||||
const json::array key
|
||||
|
@ -174,10 +174,10 @@ ircd::m::state::test(const string_view &root,
|
|||
make_key(buf, type, state_key_lb)
|
||||
};
|
||||
|
||||
return dfs(root, key, [&closure]
|
||||
return !dfs(root, key, [&closure]
|
||||
(const json::array &key, const string_view &val, const uint &, const uint &)
|
||||
{
|
||||
return closure(key, val);
|
||||
return !closure(key, val);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -278,8 +278,8 @@ ircd::m::state::dfs(const string_view &root,
|
|||
const json::array &key,
|
||||
const search_closure &closure)
|
||||
{
|
||||
bool ret{true};
|
||||
get_node(root, [&closure, &key, &ret]
|
||||
bool ret{false};
|
||||
get_node(std::nothrow, root, [&closure, &key, &ret]
|
||||
(const auto &node)
|
||||
{
|
||||
int depth(-1);
|
||||
|
|
|
@ -5259,10 +5259,10 @@ console_cmd__state__find(opt &out, const string_view &line)
|
|||
(const auto &key, const string_view &val)
|
||||
{
|
||||
out << key << " => " << val << std::endl;
|
||||
return false;
|
||||
return true;
|
||||
}};
|
||||
|
||||
m::state::test(root, type, state_key, closure);
|
||||
m::state::for_each(root, type, state_key, closure);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue