0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-02 03:32:52 +01:00

ircd:Ⓜ️ Split the origins iteration to also allow raw key iteration.

This commit is contained in:
Jason Volk 2018-03-03 06:06:15 -08:00
parent 8a5462063e
commit 7a860964c4
2 changed files with 29 additions and 16 deletions

View file

@ -251,6 +251,7 @@ struct ircd::m::room::origins
m::room room; m::room room;
bool _test_(const closure_bool &view) const;
bool test(const closure_bool &view) const; bool test(const closure_bool &view) const;
void for_each(const closure &view) const; void for_each(const closure &view) const;
size_t count() const; size_t count() const;

View file

@ -670,6 +670,31 @@ const
bool bool
ircd::m::room::origins::test(const closure_bool &view) ircd::m::room::origins::test(const closure_bool &view)
const const
{
string_view last;
char lastbuf[256];
return _test_([&last, &lastbuf, &view]
(const string_view &key)
{
const string_view &origin //TODO: XXX
{
split(key, "@").first
};
if(origin == last)
return false;
if(view(origin))
return true;
last = { lastbuf, copy(lastbuf, origin) };
return false;
});
}
bool
ircd::m::room::origins::_test_(const closure_bool &view)
const
{ {
db::index &index db::index &index
{ {
@ -681,28 +706,15 @@ const
index.begin(room.room_id) index.begin(room.room_id)
}; };
string_view last;
char lastbuf[256];
for(; bool(it); ++it) for(; bool(it); ++it)
{ {
const string_view &key{it->first}; const string_view &key //TODO: XXX
const string_view &origin_member //TODO: XXX
{ {
split(key, ":::").second lstrip(it->first, ":::")
}; };
const string_view &origin //TODO: XXX if(view(key))
{
split(origin_member, "@").first
};
if(origin == last)
continue;
if(view(origin))
return true; return true;
last = { lastbuf, copy(lastbuf, origin) };
} }
return false; return false;