Switch UserMessages off KTrie (bug 5884 part 11, r=ds).

This commit is contained in:
David Anderson 2013-08-25 12:16:07 -07:00
parent 3000445af9
commit 3985dd639a
5 changed files with 24 additions and 17 deletions

View File

@ -1,5 +1,5 @@
/**
* vim: set ts=4 :
* vim: set ts=4 sw=4 tw=99 noet :
* =============================================================================
* SourceMod
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
@ -56,7 +56,6 @@ UserMessages::UserMessages()
#ifndef USE_PROTOBUF_USERMESSAGES
: m_InterceptBuffer(m_pBase, 2500)
{
m_Names = sm_trie_create();
#else
: m_InterceptBuffer(NULL)
{
@ -70,10 +69,6 @@ UserMessages::UserMessages()
UserMessages::~UserMessages()
{
#ifndef USE_PROTOBUF_USERMESSAGES
sm_trie_destroy(m_Names);
#endif
CStack<ListenerInfo *>::iterator iter;
for (iter=m_FreeListeners.begin(); iter!=m_FreeListeners.end(); iter++)
{
@ -121,9 +116,9 @@ int UserMessages::GetMessageIndex(const char *msg)
// Can split this per engine and/or game later
return g_Cstrike15UsermessageHelpers.GetIndex(msg);
#else
int msgid;
if (!sm_trie_retrieve(m_Names, msg, reinterpret_cast<void **>(&msgid)))
int msgid;
if (!m_Names.retrieve(msg, &msgid))
{
if (m_FallbackSearch)
{
@ -135,7 +130,7 @@ int UserMessages::GetMessageIndex(const char *msg)
{
if (strcmp(msgbuf, msg) == 0)
{
sm_trie_insert(m_Names, msg, reinterpret_cast<void *>(msgid));
m_Names.insert(msg, msgid);
return msgid;
}
msgid++;
@ -145,9 +140,7 @@ int UserMessages::GetMessageIndex(const char *msg)
msgid = g_SMAPI->FindUserMessage(msg);
if (msgid != INVALID_MESSAGE_ID)
{
sm_trie_insert(m_Names, msg, reinterpret_cast<void *>(msgid));
}
m_Names.insert(msg, msgid);
}
return msgid;

View File

@ -1,5 +1,5 @@
/**
* vim: set ts=4 :
* vim: set ts=4 sw=4 tw=99 noet :
* =============================================================================
* SourceMod
* Copyright (C) 2004-2010 AlliedModders LLC. All rights reserved.
@ -34,7 +34,7 @@
#include <IUserMessages.h>
#include "sourcemm_api.h"
#include "sm_trie.h"
#include <sm_stringhashmap.h>
#include "sm_stringutil.h"
#include "CellRecipientFilter.h"
#include "sm_globals.h"
@ -153,7 +153,7 @@ private:
#ifndef USE_PROTOBUF_USERMESSAGES
bool m_FallbackSearch;
Trie *m_Names;
StringHashMap<int> m_Names;
#endif
CellRecipientFilter m_CellRecFilter;
bool m_InExec;

View File

@ -40,7 +40,6 @@
#include "AdminCache.h"
#include <inetchannel.h>
#include <bitbuf.h>
#include <sm_trie_tpl.h>
#include <tier0/dbg.h>
#include "Logger.h"
#include "ConsoleDetours.h"

View File

@ -39,7 +39,6 @@
#include "TimerSys.h"
#include "ForwardSys.h"
#include "Logger.h"
#include <sm_trie_tpl.h>
#include <sh_memory.h>
#include "logic_bridge.h"

View File

@ -108,6 +108,22 @@ public:
return &node->value;
}
/**
* @brief Wrapper around retrieve(key) for a cleaner API.
*
* @param key Key to retrieve.
* @param result Pointer to store the result, must be non-NULL.
* @return True if found, false otherwise.
*/
bool retrieve(const char *key, K *result)
{
KTrieNode *node = internal_retrieve(key);
if (!node || !node->valset)
return false;
*result = node->value;
return true;
}
/**
* @brief Inserts or updates the object stored at a key.
*