impr: Optimize build times a bit
This commit is contained in:
parent
040a606b39
commit
992f18b94b
2
lib/external/pattern_language
vendored
2
lib/external/pattern_language
vendored
@ -1 +1 @@
|
||||
Subproject commit d387be8ad6b678b516f5cd0b848019a2ff498f1b
|
||||
Subproject commit 1057425e1b945ab61b45bcfe4a2018ef1b785f75
|
@ -130,15 +130,9 @@ namespace hex {
|
||||
static void subscribe(void *token, typename E::Callback function) {
|
||||
std::scoped_lock lock(getEventMutex());
|
||||
|
||||
if (getTokenStore().contains(token)) {
|
||||
auto&& [begin, end] = getTokenStore().equal_range(token);
|
||||
const auto eventRegistered = std::any_of(begin, end, [&](auto &item) {
|
||||
return item.second->first == E::Id;
|
||||
});
|
||||
if (eventRegistered) {
|
||||
log::fatal("The token '{}' has already registered the same event ('{}')", token, wolv::type::getTypeName<E>());
|
||||
return;
|
||||
}
|
||||
if (isAlreadyRegistered(token, E::Id)) {
|
||||
log::fatal("The token '{}' has already registered the same event ('{}')", token, wolv::type::getTypeName<E>());
|
||||
return;
|
||||
}
|
||||
|
||||
getTokenStore().insert({ token, subscribe<E>(function) });
|
||||
@ -163,16 +157,7 @@ namespace hex {
|
||||
static void unsubscribe(void *token) noexcept {
|
||||
std::scoped_lock lock(getEventMutex());
|
||||
|
||||
auto &tokenStore = getTokenStore();
|
||||
auto iter = std::find_if(tokenStore.begin(), tokenStore.end(), [&](auto &item) {
|
||||
return item.first == token && item.second->first == E::Id;
|
||||
});
|
||||
|
||||
if (iter != tokenStore.end()) {
|
||||
getEvents().erase(iter->second);
|
||||
tokenStore.erase(iter);
|
||||
}
|
||||
|
||||
unsubscribe(token, E::Id);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -210,6 +195,9 @@ namespace hex {
|
||||
static std::multimap<void *, EventList::iterator>& getTokenStore();
|
||||
static EventList& getEvents();
|
||||
static std::recursive_mutex& getEventMutex();
|
||||
|
||||
static bool isAlreadyRegistered(void *token, impl::EventId id);
|
||||
static void unsubscribe(void *token, impl::EventId id);
|
||||
};
|
||||
|
||||
/* Default Events */
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <fmt/format.h>
|
||||
#include <fmt/core.h>
|
||||
#include <wolv/types/static_string.hpp>
|
||||
|
||||
namespace hex {
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string_view>
|
||||
#include <fmt/format.h>
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
namespace hex {
|
||||
|
@ -21,4 +21,30 @@ namespace hex {
|
||||
}
|
||||
|
||||
|
||||
bool EventManager::isAlreadyRegistered(void *token, impl::EventId id) {
|
||||
if (getTokenStore().contains(token)) {
|
||||
auto&& [begin, end] = getTokenStore().equal_range(token);
|
||||
|
||||
return std::any_of(begin, end, [&](auto &item) {
|
||||
return item.second->first == id;
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void EventManager::unsubscribe(void *token, impl::EventId id) {
|
||||
auto &tokenStore = getTokenStore();
|
||||
auto iter = std::find_if(tokenStore.begin(), tokenStore.end(), [&](auto &item) {
|
||||
return item.first == token && item.second->first == id;
|
||||
});
|
||||
|
||||
if (iter != tokenStore.end()) {
|
||||
getEvents().erase(iter->second);
|
||||
tokenStore.erase(iter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user