From a8b5912e98a6b582b1e351b113b0eacfbcb08258 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 15 Aug 2022 17:19:48 -0700 Subject: [PATCH] ircd::m::room::type: Add directional iteration deduced by range. --- matrix/room_type.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/matrix/room_type.cc b/matrix/room_type.cc index 987a2fc13..f1c0f858f 100644 --- a/matrix/room_type.cc +++ b/matrix/room_type.cc @@ -59,10 +59,15 @@ bool ircd::m::room::type::for_each(const closure &closure) const { + const bool desc + { + range.second < 0 || uint64_t(range.second) < range.first + }; + char buf[dbs::ROOM_TYPE_KEY_MAX_SIZE]; const string_view &key { - dbs::room_type_key(buf, room.room_id, _type, range.first, -1UL) + dbs::room_type_key(buf, room.room_id, _type, range.first, desc? -1UL: 0UL) }; auto it @@ -70,14 +75,17 @@ const dbs::room_type.begin(key) }; - for(; it; ++it) + for(; it; desc? ++it: --it) { const auto &[_type, depth, event_idx] { dbs::room_type_key(it->first) }; - if(int64_t(depth) <= range.second) + if(desc && int64_t(depth) <= range.second) + break; + + if(!desc && int64_t(depth) >= range.second) break; if(this->_type && !prefixing && this->_type != _type)