From 8ab735d002a3129a0a22f1d5ad82e8ebbc4614ab Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 16 Sep 2020 21:36:31 -0700 Subject: [PATCH] ircd::m::index: Optimize call chain; branch reduction; indirect call elimination. --- matrix/event_index.cc | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/matrix/event_index.cc b/matrix/event_index.cc index 014191f52..760a13697 100644 --- a/matrix/event_index.cc +++ b/matrix/event_index.cc @@ -53,14 +53,21 @@ ircd::m::event::idx ircd::m::index(std::nothrow_t, const event::id &event_id) { - event::idx ret{0}; - index(std::nothrow, event_id, [&ret] - (const event::idx &event_idx) + auto &column { - ret = event_idx; - }); + dbs::event_idx + }; - return ret; + bool found; + alignas(8) char buf[8] {0}; + if(likely(event_id)) + read(column, event_id, found, buf); + + constexpr bool safety(false); // we know buf is the right size + return byte_view + { + buf + }; } bool @@ -73,13 +80,10 @@ ircd::m::index(std::nothrow_t, dbs::event_idx }; - if(!event_id) - return false; - - return column(event_id, std::nothrow, [&closure] + return event_id && column(event_id, std::nothrow, [&closure] (const string_view &value) { - const event::idx &event_idx + const event::idx event_idx { byte_view(value) };