From 6c71ec39b29725b9b04ef8bc75275f49d203e884 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 18 Dec 2020 21:09:47 -0800 Subject: [PATCH] ircd::m: Parallel event::idx convenience for event::auth; simplify definitions. --- include/ircd/m/event/auth.h | 13 +----------- include/ircd/m/event/index.h | 3 ++- include/ircd/m/event/prev.h | 13 +----------- matrix/event_index.cc | 41 ++++++++++++++++++++++++------------ 4 files changed, 32 insertions(+), 38 deletions(-) diff --git a/include/ircd/m/event/auth.h b/include/ircd/m/event/auth.h index 058d149f6..defa75f1d 100644 --- a/include/ircd/m/event/auth.h +++ b/include/ircd/m/event/auth.h @@ -56,20 +56,9 @@ inline ircd::vector_view ircd::m::event::auth::idxs(event::idx (&out)[N]) const { - event::id buf[N]; - const auto &ids - { - auth::ids(buf) - }; - - const auto &found - { - m::index(out, ids) - }; - return vector_view ( - out, out + ids.size() + out, m::index(out, *this) ); } diff --git a/include/ircd/m/event/index.h b/include/ircd/m/event/index.h index b34a2e789..4d46a0788 100644 --- a/include/ircd/m/event/index.h +++ b/include/ircd/m/event/index.h @@ -16,8 +16,9 @@ namespace ircd::m // Parallel query; returns number of successful results (positions are fixed) size_t index(const vector_view &out, const vector_view &in); - // Parallel query; returns number of successful results (positions are fixed) + // Parallel query; returns number number of ids. Successful results non-zero. size_t index(const vector_view &out, const m::event::prev &); + size_t index(const vector_view &out, const m::event::auth &); // Responds with idx in closure; returns false if no action. bool index(std::nothrow_t, const event::id &, const event::closure_idx &); diff --git a/include/ircd/m/event/prev.h b/include/ircd/m/event/prev.h index 7772b9298..0884cd7ee 100644 --- a/include/ircd/m/event/prev.h +++ b/include/ircd/m/event/prev.h @@ -63,20 +63,9 @@ inline ircd::vector_view ircd::m::event::prev::idxs(event::idx (&out)[N]) const { - event::id buf[N]; - const auto &ids - { - prev::ids(buf) - }; - - const auto &found - { - m::index(out, ids) - }; - return vector_view ( - out, out + ids.size() + out, m::index(out, *this) ); } diff --git a/matrix/event_index.cc b/matrix/event_index.cc index d96db5c4b..2966496f1 100644 --- a/matrix/event_index.cc +++ b/matrix/event_index.cc @@ -100,25 +100,40 @@ ircd::m::index(std::nothrow_t, size_t ircd::m::index(const vector_view &out, - const event::prev &prev) + const event::auth &auth) { - const auto num + event::id ids[event::auth::MAX]; + const auto &event_ids { - std::min(prev.prev_events_count(), event::prev::MAX) + auth.ids(ids) }; - size_t i(0); - event::id event_id[num]; - m::for_each(prev, [&num, &i, &event_id] - (const auto &prev_id) + const auto &found { - assert(i < num); - event_id[i++] = prev_id; - return i < num; - }); + index(out, event_ids) + }; - assert(i == num); - return index(out, vector_view(event_id, i)); + assert(found <= event_ids.size()); + return event_ids.size(); +} + +size_t +ircd::m::index(const vector_view &out, + const event::prev &prev) +{ + event::id ids[event::prev::MAX]; + const auto &event_ids + { + prev.ids(ids) + }; + + const auto &found + { + index(out, event_ids) + }; + + assert(found <= event_ids.size()); + return event_ids.size(); } size_t