From 13003986bc59afa7ef1a1323e0a1b13474407217 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 12 May 2020 17:27:44 -0700 Subject: [PATCH] ircd::m::vm::eval: Minor static interface reorg. --- include/ircd/m/vm.h | 11 ++-- matrix/vm_eval.cc | 119 ++++++++++++++++++++++---------------------- 2 files changed, 65 insertions(+), 65 deletions(-) diff --git a/include/ircd/m/vm.h b/include/ircd/m/vm.h index e38edd00c..b34e8f01a 100644 --- a/include/ircd/m/vm.h +++ b/include/ircd/m/vm.h @@ -93,10 +93,6 @@ struct ircd::m::vm::eval vm::phase phase {vm::phase(0)}; bool room_internal {false}; - static bool for_each_pdu(const std::function &); - static const event *find_pdu(const eval &, const event::id &); - static const event *find_pdu(const event::id &); - void mfetch_keys() const; public: @@ -120,11 +116,16 @@ struct ircd::m::vm::eval ~eval() noexcept; static bool for_each(const ctx::ctx *const &, const std::function &); - static bool for_each(const std::function &); static size_t count(const ctx::ctx *const &); + + static bool for_each(const std::function &); + static bool for_each_pdu(const std::function &); + static const event *find_pdu(const eval &, const event::id &); + static const event *find_pdu(const event::id &); static size_t count(const event::id &); static eval *find(const event::id &); static eval &get(const event::id &); + static bool sequnique(const uint64_t &seq); static eval *seqnext(const uint64_t &seq); static eval *seqmax(); diff --git a/matrix/vm_eval.cc b/matrix/vm_eval.cc index 45e00f69a..eb499a488 100644 --- a/matrix/vm_eval.cc +++ b/matrix/vm_eval.cc @@ -197,16 +197,60 @@ ircd::m::vm::eval::count(const event::id &event_id) return ret; } -size_t -ircd::m::vm::eval::count(const ctx::ctx *const &c) +const ircd::m::event * +ircd::m::vm::eval::find_pdu(const event::id &event_id) { - return std::count_if(begin(eval::list), end(eval::list), [&c] - (const eval *const &eval) + const m::event *ret{nullptr}; + for_each_pdu([&ret, &event_id] + (const m::event &event) { - return eval->ctx == c; + if(event.event_id != event_id) + return true; + + ret = std::addressof(event); + return false; }); + + return ret; } +const ircd::m::event * +ircd::m::vm::eval::find_pdu(const eval &eval, + const event::id &event_id) +{ + const m::event *ret{nullptr}; + for(const auto &event : eval.pdus) + { + if(event.event_id != event_id) + continue; + + ret = std::addressof(event); + break; + } + + return ret; +} + +bool +ircd::m::vm::eval::for_each_pdu(const std::function &closure) +{ + return for_each([&closure](eval &e) + { + if(!empty(e.pdus)) + { + for(const auto &pdu : e.pdus) + if(!closure(pdu)) + return false; + } + else if(e.event_) + { + if(!closure(*e.event_)) + return false; + } + + return true; + }); +} bool ircd::m::vm::eval::for_each(const std::function &closure) { @@ -217,6 +261,16 @@ ircd::m::vm::eval::for_each(const std::function &closure) return true; } +size_t +ircd::m::vm::eval::count(const ctx::ctx *const &c) +{ + return std::count_if(begin(eval::list), end(eval::list), [&c] + (const eval *const &eval) + { + return eval->ctx == c; + }); +} + bool ircd::m::vm::eval::for_each(const ctx::ctx *const &c, const std::function &closure) @@ -411,58 +465,3 @@ const this->pdus.size(), }; } - -const ircd::m::event * -ircd::m::vm::eval::find_pdu(const event::id &event_id) -{ - const m::event *ret{nullptr}; - for_each_pdu([&ret, &event_id] - (const m::event &event) - { - if(event.event_id != event_id) - return true; - - ret = std::addressof(event); - return false; - }); - - return ret; -} - -const ircd::m::event * -ircd::m::vm::eval::find_pdu(const eval &eval, - const event::id &event_id) -{ - const m::event *ret{nullptr}; - for(const auto &event : eval.pdus) - { - if(event.event_id != event_id) - continue; - - ret = std::addressof(event); - break; - } - - return ret; -} - -bool -ircd::m::vm::eval::for_each_pdu(const std::function &closure) -{ - return for_each([&closure](eval &e) - { - if(!empty(e.pdus)) - { - for(const auto &pdu : e.pdus) - if(!closure(pdu)) - return false; - } - else if(e.event_) - { - if(!closure(*e.event_)) - return false; - } - - return true; - }); -}