Switch EventManager off KTrie (bug 5884 part 13, r=ds).
Switch EventManager off KTrie (
bug 5884 part 13, r=ds).
1.1 --- a/core/EventManager.cpp Sun Aug 25 12:17:25 2013 -0700
1.2 +++ b/core/EventManager.cpp Sun Aug 25 12:17:26 2013 -0700
1.3 @@ -57,14 +57,10 @@
1.4
1.5 EventManager::EventManager() : m_EventType(0)
1.6 {
1.7 - /* Create an event lookup trie */
1.8 - m_EventHooks = sm_trie_create();
1.9 }
1.10
1.11 EventManager::~EventManager()
1.12 {
1.13 - sm_trie_destroy(m_EventHooks);
1.14 -
1.15 /* Free memory used by EventInfo structs if any */
1.16 CStack<EventInfo *>::iterator iter;
1.17 for (iter = m_FreeEvents.begin(); iter != m_FreeEvents.end(); iter++)
1.18 @@ -183,7 +179,7 @@
1.19 }
1.20
1.21 /* If a hook structure does not exist... */
1.22 - if (!sm_trie_retrieve(m_EventHooks, name, (void **)&pHook))
1.23 + if (!m_EventHooks.retrieve(name, &pHook))
1.24 {
1.25 EventHookList *pHookList;
1.26 IPlugin *plugin = scripts->FindPluginByContext(pFunction->GetParentContext()->GetContext());
1.27 @@ -221,7 +217,7 @@
1.28
1.29 /* Add hook structure to hook lists */
1.30 pHookList->push_back(pHook);
1.31 - sm_trie_insert(m_EventHooks, name, pHook);
1.32 + m_EventHooks.insert(name, pHook);
1.33
1.34 return EventHookErr_Okay;
1.35 }
1.36 @@ -267,7 +263,7 @@
1.37 IChangeableForward **pEventForward;
1.38
1.39 /* If hook does not exist at all */
1.40 - if (!sm_trie_retrieve(m_EventHooks, name, (void **)&pHook))
1.41 + if (!m_EventHooks.retrieve(name, &pHook))
1.42 {
1.43 return EventHookErr_NotActive;
1.44 }
1.45 @@ -317,7 +313,7 @@
1.46 pHookList->remove(pHook);
1.47
1.48 /* Delete entry in trie */
1.49 - sm_trie_delete(m_EventHooks, name);
1.50 + m_EventHooks.remove(name);
1.51
1.52 /* Free the cached name */
1.53 delete pHook->name;
1.54 @@ -396,7 +392,7 @@
1.55
1.56 name = pEvent->GetName();
1.57
1.58 - if (sm_trie_retrieve(m_EventHooks, name, reinterpret_cast<void **>(&pHook)))
1.59 + if (m_EventHooks.retrieve(name, &pHook))
1.60 {
1.61 /* Push the event onto the event stack. The reference count is increased to make sure
1.62 * the structure is not garbage collected in between now and the post hook.
1.63 @@ -503,7 +499,7 @@
1.64 {
1.65 assert(pHook->pPostHook == NULL);
1.66 assert(pHook->pPreHook == NULL);
1.67 - sm_trie_delete(m_EventHooks, pHook->name);
1.68 + m_EventHooks.remove(pHook->name);
1.69 delete pHook->name;
1.70 delete pHook;
1.71 }
2.1 --- a/core/EventManager.h Sun Aug 25 12:17:25 2013 -0700
2.2 +++ b/core/EventManager.h Sun Aug 25 12:17:26 2013 -0700
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * vim: set ts=4 :
2.6 + * vim: set ts=4 sw=4 tw=99 noet :
2.7 * =============================================================================
2.8 * SourceMod
2.9 * Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
2.10 @@ -34,7 +34,7 @@
2.11
2.12 #include "sm_globals.h"
2.13 #include "sourcemm_api.h"
2.14 -#include "sm_trie.h"
2.15 +#include <sm_namehashset.h>
2.16 #include <sh_list.h>
2.17 #include <sh_stack.h>
2.18 #include <IHandleSys.h>
2.19 @@ -70,6 +70,11 @@
2.20 bool postCopy;
2.21 unsigned int refCount;
2.22 char *name;
2.23 +
2.24 + static inline bool matches(const char *name, const EventHook *hook)
2.25 + {
2.26 + return strcmp(name, hook->name) == 0;
2.27 + }
2.28 };
2.29
2.30 enum EventHookMode
2.31 @@ -127,7 +132,7 @@
2.32 bool OnFireEvent_Post(IGameEvent *pEvent, bool bDontBroadcast);
2.33 private:
2.34 HandleType_t m_EventType;
2.35 - Trie *m_EventHooks;
2.36 + NameHashSet<EventHook *> m_EventHooks;
2.37 CStack<EventInfo *> m_FreeEvents;
2.38 CStack<EventHook *> m_EventStack;
2.39 CStack<IGameEvent *> m_EventCopies;