Commit eeea70b4 authored by Dominik Charousset's avatar Dominik Charousset

Avoid `dynamic_cast` in `joined_groups()`

parent 1f3e8d3c
......@@ -40,8 +40,11 @@ bool abstract_group::subscription::matches(const token& what) {
if (what.subtype != attachable::token::subscription) {
return false;
}
auto& ot = *reinterpret_cast<const subscription_token*>(what.ptr);
return ot.group == m_group;
if (what.ptr) {
auto& ot = *reinterpret_cast<const subscription_token*>(what.ptr);
return ot.group == m_group;
}
return true;
}
abstract_group::module::module(std::string mname) : m_name(std::move(mname)) {
......
......@@ -88,11 +88,12 @@ void local_actor::leave(const group& what) {
std::vector<group> local_actor::joined_groups() const {
std::vector<group> result;
result.reserve(20);
attachable::token stk{attachable::token::subscription, nullptr};
std::unique_lock<std::mutex> guard{m_mtx};
for (attachable* i = m_attachables_head.get(); i != 0; i = i->next.get()) {
auto sptr = dynamic_cast<abstract_group::subscription*>(i);
if (sptr) {
result.emplace_back(sptr->group());
if (i->matches(stk)) {
auto ptr = static_cast<abstract_group::subscription*>(i);
result.emplace_back(ptr->group());
}
}
return result;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment