mirror of
https://github.com/matrix-construct/construct
synced 2024-05-29 00:03:45 +02:00
ircd:Ⓜ️:vm::eval: Use closure_bool for_each(); reduce direct instance_list iteration.
This commit is contained in:
parent
2dc58b55d5
commit
e45dc31797
|
@ -36,6 +36,9 @@ namespace ircd::m::vm
|
|||
struct ircd::m::vm::eval
|
||||
:instance_list<eval>
|
||||
{
|
||||
using each_eval = closure_bool<std::function, eval &>;
|
||||
using each_pdu = closure_bool<std::function, const event &>;
|
||||
|
||||
static uint64_t id_ctr;
|
||||
static uint executing;
|
||||
static uint injecting;
|
||||
|
@ -84,11 +87,9 @@ struct ircd::m::vm::eval
|
|||
~eval() noexcept;
|
||||
|
||||
// Tools for all evals
|
||||
static bool for_each(const std::function<bool (eval &)> &);
|
||||
static bool for_each_pdu(const std::function<bool (const event &)> &);
|
||||
|
||||
// Tools for all evals sharing this ircd::context
|
||||
static bool for_each(const ctx::ctx *const &, const std::function<bool (eval &)> &);
|
||||
static bool for_each(const each_eval &);
|
||||
static bool for_each_pdu(const each_pdu &);
|
||||
static bool for_each(const ctx::ctx *const &, const each_eval &);
|
||||
static size_t count(const ctx::ctx *const &);
|
||||
|
||||
// Event snoop interface
|
||||
|
|
|
@ -395,18 +395,20 @@ ircd::m::vm::eval::count(const ctx::ctx *const &c)
|
|||
|
||||
bool
|
||||
ircd::m::vm::eval::for_each(const ctx::ctx *const &c,
|
||||
const std::function<bool (eval &)> &closure)
|
||||
const each_eval &closure)
|
||||
{
|
||||
for(eval *const &eval : eval::list)
|
||||
if(eval->ctx == c)
|
||||
if(!closure(*eval))
|
||||
return for_each([&c, &closure](eval &e)
|
||||
{
|
||||
if(e.ctx == c)
|
||||
if(!closure(e))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::vm::eval::for_each_pdu(const std::function<bool (const event &)> &closure)
|
||||
ircd::m::vm::eval::for_each_pdu(const each_pdu &closure)
|
||||
{
|
||||
return for_each([&closure](eval &e)
|
||||
{
|
||||
|
@ -427,7 +429,7 @@ ircd::m::vm::eval::for_each_pdu(const std::function<bool (const event &)> &closu
|
|||
}
|
||||
|
||||
bool
|
||||
ircd::m::vm::eval::for_each(const std::function<bool (eval &)> &closure)
|
||||
ircd::m::vm::eval::for_each(const each_eval &closure)
|
||||
{
|
||||
for(eval *const &eval : eval::list)
|
||||
if(!closure(*eval))
|
||||
|
|
|
@ -16644,36 +16644,35 @@ console_cmd__vm(opt &out, const string_view &line)
|
|||
<< std::left << std::setw(20) << "STATE_KEY" << " "
|
||||
<< std::endl;
|
||||
|
||||
for(const auto *const &eval : m::vm::eval::list)
|
||||
m::vm::eval::for_each([&out](const auto &eval)
|
||||
{
|
||||
assert(eval);
|
||||
assert(eval->ctx);
|
||||
assert(eval.ctx);
|
||||
|
||||
out
|
||||
<< std::right << std::setw(8) << eval->id << " "
|
||||
<< std::right << std::setw(4) << (eval->ctx? ctx::id(*eval->ctx) : 0UL) << " "
|
||||
<< std::left << std::setw(8) << (eval->ctx? trunc(ctx::name(*eval->ctx), 8) : string_view{}) << " "
|
||||
<< std::left << std::setw(24) << trunc(eval->opts->node_id?: eval->opts->user_id, 24) << " "
|
||||
<< std::right << std::setw(4) << eval->pdus.size() << " "
|
||||
<< std::right << std::setw(4) << eval->evaluated << " "
|
||||
<< std::right << std::setw(4) << eval->accepted << " "
|
||||
<< std::right << std::setw(4) << eval->faulted << " "
|
||||
<< std::right << std::setw(8) << (eval->parent? eval->parent->id : 0UL) << " "
|
||||
<< std::right << std::setw(9) << eval->sequence << " "
|
||||
<< std::right << std::setw(4) << (eval->hook? eval->hook->id(): 0U) << " "
|
||||
<< std::left << std::setw(10) << trunc(reflect(eval->phase), 10) << " "
|
||||
<< std::right << std::setw(6) << (eval->txn? eval->txn->bytes() : 0UL) << " "
|
||||
<< std::right << std::setw(5) << (eval->txn? eval->txn->size() : 0UL) << " "
|
||||
<< std::right << std::setw(8) << (eval->event_ && eval->event_id? long(json::get<"depth"_>(*eval->event_)) : -1L) << " "
|
||||
<< std::right << std::setw(5) << eval->room_version << " "
|
||||
<< std::left << std::setw(40) << trunc(eval->room_id, 40) << " "
|
||||
<< std::left << std::setw(60) << trunc(eval->event_id, 60) << " "
|
||||
<< std::left << std::setw(20) << trunc(eval->event_? json::get<"sender"_>(*eval->event_) : json::string{}, 20) << " "
|
||||
<< std::left << std::setw(20) << trunc(eval->event_? json::get<"type"_>(*eval->event_) : json::string{}, 20) << " "
|
||||
<< std::left << std::setw(20) << trunc(eval->event_? json::get<"state_key"_>(*eval->event_) : json::string{}, 20) << " "
|
||||
<< std::right << std::setw(8) << eval.id << " "
|
||||
<< std::right << std::setw(4) << (eval.ctx? ctx::id(*eval.ctx) : 0UL) << " "
|
||||
<< std::left << std::setw(8) << (eval.ctx? trunc(ctx::name(*eval.ctx), 8) : string_view{}) << " "
|
||||
<< std::left << std::setw(24) << trunc(eval.opts->node_id?: eval.opts->user_id, 24) << " "
|
||||
<< std::right << std::setw(4) << eval.pdus.size() << " "
|
||||
<< std::right << std::setw(4) << eval.evaluated << " "
|
||||
<< std::right << std::setw(4) << eval.accepted << " "
|
||||
<< std::right << std::setw(4) << eval.faulted << " "
|
||||
<< std::right << std::setw(8) << (eval.parent? eval.parent->id : 0UL) << " "
|
||||
<< std::right << std::setw(9) << eval.sequence << " "
|
||||
<< std::right << std::setw(4) << (eval.hook? eval.hook->id(): 0U) << " "
|
||||
<< std::left << std::setw(10) << trunc(reflect(eval.phase), 10) << " "
|
||||
<< std::right << std::setw(6) << (eval.txn? eval.txn->bytes() : 0UL) << " "
|
||||
<< std::right << std::setw(5) << (eval.txn? eval.txn->size() : 0UL) << " "
|
||||
<< std::right << std::setw(8) << (eval.event_ && eval.event_id? long(json::get<"depth"_>(*eval.event_)) : -1L) << " "
|
||||
<< std::right << std::setw(5) << eval.room_version << " "
|
||||
<< std::left << std::setw(40) << trunc(eval.room_id, 40) << " "
|
||||
<< std::left << std::setw(60) << trunc(eval.event_id, 60) << " "
|
||||
<< std::left << std::setw(20) << trunc(eval.event_? json::get<"sender"_>(*eval.event_) : json::string{}, 20) << " "
|
||||
<< std::left << std::setw(20) << trunc(eval.event_? json::get<"type"_>(*eval.event_) : json::string{}, 20) << " "
|
||||
<< std::left << std::setw(20) << trunc(eval.event_? json::get<"state_key"_>(*eval.event_) : json::string{}, 20) << " "
|
||||
<< std::endl
|
||||
;
|
||||
}
|
||||
});
|
||||
|
||||
out << std::endl;
|
||||
|
||||
|
|
Loading…
Reference in a new issue