From 74f3df83dbc9fc4b43b8cfb9d71ba02234bd5c4a Mon Sep 17 00:00:00 2001 From: Michele Caini Date: Wed, 1 Apr 2020 21:19:38 +0200 Subject: [PATCH] dispatcher: use only sequential indexes now --- src/entt/signal/dispatcher.hpp | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/entt/signal/dispatcher.hpp b/src/entt/signal/dispatcher.hpp index e5e858114..9a3bf4a9c 100644 --- a/src/entt/signal/dispatcher.hpp +++ b/src/entt/signal/dispatcher.hpp @@ -33,7 +33,6 @@ class dispatcher { virtual ~basic_pool() = default; virtual void publish() = 0; virtual void clear() ENTT_NOEXCEPT = 0; - virtual id_type type_id() const ENTT_NOEXCEPT = 0; }; template @@ -69,10 +68,6 @@ class dispatcher { events.emplace_back(std::forward(args)...); } - id_type type_id() const ENTT_NOEXCEPT override { - return type_info::id(); - } - private: signal_type signal{}; std::vector events; @@ -81,14 +76,14 @@ class dispatcher { template pool_handler & assure() { static_assert(std::is_same_v>); - static std::size_t index{pools.size()}; + const auto index = type_index::value(); - if(const auto length = pools.size(); !(index < length) || pools[index]->type_id() != type_info::id()) { - for(index = {}; index < length && pools[index]->type_id() != type_info::id(); ++index); + if(!(index < pools.size())) { + pools.resize(index+1); + } - if(index == pools.size()) { - pools.emplace_back(new pool_handler{}); - } + if(!pools[index]) { + pools[index].reset(new pool_handler{}); } return static_cast &>(*pools[index]); @@ -187,7 +182,9 @@ public: void clear() { if constexpr(sizeof...(Event) == 0) { for(auto &&cpool: pools) { - cpool->clear(); + if(cpool) { + cpool->clear(); + } } } else { (assure().clear(), ...); @@ -217,7 +214,9 @@ public: */ void update() const { for(auto pos = pools.size(); pos; --pos) { - pools[pos-1]->publish(); + if(auto &&cpool = pools[pos-1]; cpool) { + cpool->publish(); + } } }