1
0
mirror of synced 2025-01-11 05:42:15 +01:00

impr: Optimize build times a bit

This commit is contained in:
WerWolv 2024-12-14 19:15:49 +01:00
parent 040a606b39
commit 992f18b94b
5 changed files with 36 additions and 22 deletions

@ -1 +1 @@
Subproject commit d387be8ad6b678b516f5cd0b848019a2ff498f1b
Subproject commit 1057425e1b945ab61b45bcfe4a2018ef1b785f75

View File

@ -130,16 +130,10 @@ 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) {
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 */

View File

@ -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 {

View File

@ -1,7 +1,7 @@
#pragma once
#include <string_view>
#include <fmt/format.h>
#include <fmt/core.h>
#include <fmt/ranges.h>
namespace hex {

View File

@ -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);
}
}
}