Switch UserMessages off KTrie (bug 5884 part 11, r=ds).
Switch UserMessages off KTrie (
bug 5884 part 11, r=ds).
1.1 --- a/core/UserMessages.cpp Sun Aug 25 12:15:27 2013 -0700
1.2 +++ b/core/UserMessages.cpp Sun Aug 25 12:16:07 2013 -0700
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * vim: set ts=4 :
1.6 + * vim: set ts=4 sw=4 tw=99 noet :
1.7 * =============================================================================
1.8 * SourceMod
1.9 * Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
1.10 @@ -56,7 +56,6 @@
1.11 #ifndef USE_PROTOBUF_USERMESSAGES
1.12 : m_InterceptBuffer(m_pBase, 2500)
1.13 {
1.14 - m_Names = sm_trie_create();
1.15 #else
1.16 : m_InterceptBuffer(NULL)
1.17 {
1.18 @@ -70,10 +69,6 @@
1.19
1.20 UserMessages::~UserMessages()
1.21 {
1.22 -#ifndef USE_PROTOBUF_USERMESSAGES
1.23 - sm_trie_destroy(m_Names);
1.24 -#endif
1.25 -
1.26 CStack<ListenerInfo *>::iterator iter;
1.27 for (iter=m_FreeListeners.begin(); iter!=m_FreeListeners.end(); iter++)
1.28 {
1.29 @@ -121,9 +116,9 @@
1.30 // Can split this per engine and/or game later
1.31 return g_Cstrike15UsermessageHelpers.GetIndex(msg);
1.32 #else
1.33 +
1.34 int msgid;
1.35 -
1.36 - if (!sm_trie_retrieve(m_Names, msg, reinterpret_cast<void **>(&msgid)))
1.37 + if (!m_Names.retrieve(msg, &msgid))
1.38 {
1.39 if (m_FallbackSearch)
1.40 {
1.41 @@ -135,7 +130,7 @@
1.42 {
1.43 if (strcmp(msgbuf, msg) == 0)
1.44 {
1.45 - sm_trie_insert(m_Names, msg, reinterpret_cast<void *>(msgid));
1.46 + m_Names.insert(msg, msgid);
1.47 return msgid;
1.48 }
1.49 msgid++;
1.50 @@ -145,9 +140,7 @@
1.51 msgid = g_SMAPI->FindUserMessage(msg);
1.52
1.53 if (msgid != INVALID_MESSAGE_ID)
1.54 - {
1.55 - sm_trie_insert(m_Names, msg, reinterpret_cast<void *>(msgid));
1.56 - }
1.57 + m_Names.insert(msg, msgid);
1.58 }
1.59
1.60 return msgid;
2.1 --- a/core/UserMessages.h Sun Aug 25 12:15:27 2013 -0700
2.2 +++ b/core/UserMessages.h Sun Aug 25 12:16:07 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 <IUserMessages.h>
2.13 #include "sourcemm_api.h"
2.14 -#include "sm_trie.h"
2.15 +#include <sm_stringhashmap.h>
2.16 #include "sm_stringutil.h"
2.17 #include "CellRecipientFilter.h"
2.18 #include "sm_globals.h"
2.19 @@ -153,7 +153,7 @@
2.20 #ifndef USE_PROTOBUF_USERMESSAGES
2.21 bool m_FallbackSearch;
2.22
2.23 - Trie *m_Names;
2.24 + StringHashMap<int> m_Names;
2.25 #endif
2.26 CellRecipientFilter m_CellRecFilter;
2.27 bool m_InExec;
3.1 --- a/core/smn_console.cpp Sun Aug 25 12:15:27 2013 -0700
3.2 +++ b/core/smn_console.cpp Sun Aug 25 12:16:07 2013 -0700
3.3 @@ -40,7 +40,6 @@
3.4 #include "AdminCache.h"
3.5 #include <inetchannel.h>
3.6 #include <bitbuf.h>
3.7 -#include <sm_trie_tpl.h>
3.8 #include <tier0/dbg.h>
3.9 #include "Logger.h"
3.10 #include "ConsoleDetours.h"
4.1 --- a/core/smn_core.cpp Sun Aug 25 12:15:27 2013 -0700
4.2 +++ b/core/smn_core.cpp Sun Aug 25 12:16:07 2013 -0700
4.3 @@ -39,7 +39,6 @@
4.4 #include "TimerSys.h"
4.5 #include "ForwardSys.h"
4.6 #include "Logger.h"
4.7 -#include <sm_trie_tpl.h>
4.8 #include <sh_memory.h>
4.9 #include "logic_bridge.h"
4.10
5.1 --- a/public/sm_trie_tpl.h Sun Aug 25 12:15:27 2013 -0700
5.2 +++ b/public/sm_trie_tpl.h Sun Aug 25 12:16:07 2013 -0700
5.3 @@ -109,6 +109,22 @@
5.4 }
5.5
5.6 /**
5.7 + * @brief Wrapper around retrieve(key) for a cleaner API.
5.8 + *
5.9 + * @param key Key to retrieve.
5.10 + * @param result Pointer to store the result, must be non-NULL.
5.11 + * @return True if found, false otherwise.
5.12 + */
5.13 + bool retrieve(const char *key, K *result)
5.14 + {
5.15 + KTrieNode *node = internal_retrieve(key);
5.16 + if (!node || !node->valset)
5.17 + return false;
5.18 + *result = node->value;
5.19 + return true;
5.20 + }
5.21 +
5.22 + /**
5.23 * @brief Inserts or updates the object stored at a key.
5.24 *
5.25 * @param key Key to update or insert.