Store connected slots in a vector rather than a map

This commit is contained in:
Thomas Goyne 2014-05-26 08:54:29 -07:00
parent 81b942ea6e
commit 4da1443194
1 changed files with 11 additions and 9 deletions

View File

@ -15,7 +15,6 @@
#pragma once #pragma once
#include <boost/config.hpp> #include <boost/config.hpp>
#include <map>
#include <functional> #include <functional>
#include <memory> #include <memory>
#include <vector> #include <vector>
@ -128,15 +127,20 @@ namespace detail {
template<typename... Args> template<typename... Args>
class Signal final : private detail::SignalBase { class Signal final : private detail::SignalBase {
using Slot = std::function<void(Args...)>; using Slot = std::function<void(Args...)>;
std::map<detail::ConnectionToken*, Slot> slots; /// Signals currently connected to this slot std::vector<std::pair<detail::ConnectionToken*, Slot>> slots; /// Signals currently connected to this slot
void Disconnect(detail::ConnectionToken *tok) override { void Disconnect(detail::ConnectionToken *tok) override {
slots.erase(tok); for (auto it = begin(slots), e = end(slots); it != e; ++it) {
if (tok == it->first) {
slots.erase(it);
return;
}
}
} }
UnscopedConnection DoConnect(Slot sig) { UnscopedConnection DoConnect(Slot sig) {
auto token = MakeToken(); auto token = MakeToken();
slots.emplace(token, sig); slots.emplace_back(token, sig);
return UnscopedConnection(token); return UnscopedConnection(token);
} }
@ -153,11 +157,9 @@ public:
/// The order in which connected slots are called is undefined and should /// The order in which connected slots are called is undefined and should
/// not be relied on /// not be relied on
void operator()(Args... args) { void operator()(Args... args) {
for (auto cur = slots.begin(); cur != slots.end(); ) { for (size_t i = slots.size(); i > 0; --i) {
if (Blocked(cur->first)) if (!Blocked(slots[i - 1].first))
++cur; slots[i - 1].second(args...);
else
(cur++)->second(args...);
} }
} }