From 08d45dc838af53876663ad26fced8fc81d72c16a Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Sat, 30 Jun 2018 21:55:01 -0700 Subject: [PATCH] ircd::m: Generalize room::lonly into more efficient room::origins::only(origin). --- include/ircd/m/room.h | 1 + ircd/m/room.cc | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/include/ircd/m/room.h b/include/ircd/m/room.h index 7caf09780..e7c85515b 100644 --- a/include/ircd/m/room.h +++ b/include/ircd/m/room.h @@ -343,6 +343,7 @@ struct ircd::m::room::origins bool test(const closure_bool &view) const; void for_each(const closure &view) const; bool has(const string_view &origin) const; + bool only(const string_view &origin) const; size_t count() const; origins(const m::room &room) diff --git a/ircd/m/room.cc b/ircd/m/room.cc index 59d126037..97929afea 100644 --- a/ircd/m/room.cc +++ b/ircd/m/room.cc @@ -171,13 +171,7 @@ ircd::m::room::lonly() const { const origins origins(*this); - if(origins.count() != 1) - return false; - - if(!origins.has(m::my_host())) - return false; - - return true; + return origins.only(my_host()); } bool @@ -1571,6 +1565,28 @@ const return ret; } +/// Tests if argument is the only origin in the room. +/// If a zero or more than one origins exist, returns false. If the only origin +/// in the room is the argument origin, returns true. +bool +ircd::m::room::origins::only(const string_view &origin) +const +{ + bool ret{false}; + test([&ret, &origin] + (const string_view &origin_) + { + if(origin == origin_) + ret = true; + else if(ret) + ret = false; + + return ret; + }); + + return ret; +} + bool ircd::m::room::origins::has(const string_view &origin) const