Przeglądaj źródła

fixed dispatcher + minor changes

Michele Caini 8 lat temu
rodzic
commit
c9bf38ce36
2 zmienionych plików z 6 dodań i 12 usunięć
  1. 3 7
      src/entt/signal/dispatcher.hpp
  2. 3 5
      src/entt/signal/sigh.hpp

+ 3 - 7
src/entt/signal/dispatcher.hpp

@@ -47,14 +47,10 @@ class Dispatcher final {
         using sink_type = typename SigH<void(const Event &)>::sink_type;
 
         void publish() override {
-            for(const auto &event: events[current]) {
-                signal.publish(event);
-            }
-
-            events[current].clear();
-
-            ++current;
+            const auto &curr = current++;
             current %= std::extent<decltype(events)>::value;
+            std::for_each(events[curr].cbegin(), events[curr].cend(), [this](const auto &event) { signal.publish(event); });
+            events[curr].clear();
         }
 
         inline sink_type sink() noexcept {

+ 3 - 5
src/entt/signal/sigh.hpp

@@ -306,9 +306,9 @@ public:
      * @param args Arguments to use to invoke listeners.
      */
     void publish(Args... args) {
-        for(auto &&call: calls) {
+        std::for_each(calls.begin(), calls.end(), [&args...](auto &&call) {
             call.second(call.first, args...);
-        }
+        });
     }
 
     /**
@@ -319,9 +319,7 @@ public:
     collector_type collect(Args... args) {
         collector_type collector;
 
-        for(auto pos = calls.size(); pos; --pos) {
-            auto &call = calls[pos-1];
-
+        for(auto &&call: calls) {
             if(!this->invoke(collector, call.second, call.first, args...)) {
                 break;
             }