Switch sm_srvcmds off KTrie (bug 5884 part 12, r=ds).
authorDavid Anderson <dvander@alliedmods.net>
Sun Aug 25 12:17:25 2013 -0700 (2013-08-25)
changeset 407484b49d686a77
parent 4073 56283c919b7b
child 4075 bf9f4d0fd9fb
Switch sm_srvcmds off KTrie (bug 5884 part 12, r=ds).
core/sm_srvcmds.cpp
core/sm_srvcmds.h
     1.1 --- a/core/sm_srvcmds.cpp	Sun Aug 25 12:16:07 2013 -0700
     1.2 +++ b/core/sm_srvcmds.cpp	Sun Aug 25 12:17:25 2013 -0700
     1.3 @@ -1,5 +1,5 @@
     1.4  /**
     1.5 - * vim: set ts=4 sw=4 :
     1.6 + * vim: set ts=4 sw=4 tw=99 noet :
     1.7   * =============================================================================
     1.8   * SourceMod
     1.9   * Copyright (C) 2004-2009 AlliedModders LLC.  All rights reserved.
    1.10 @@ -42,14 +42,11 @@
    1.11  
    1.12  RootConsoleMenu::RootConsoleMenu()
    1.13  {
    1.14 -	m_pCommands = sm_trie_create();
    1.15  	m_CfgExecDone = false;
    1.16  }
    1.17  
    1.18  RootConsoleMenu::~RootConsoleMenu()
    1.19  {
    1.20 -	sm_trie_destroy(m_pCommands);
    1.21 -
    1.22  	List<ConsoleEntry *>::iterator iter;
    1.23  	for (iter=m_Menu.begin(); iter!=m_Menu.end(); iter++)
    1.24  	{
    1.25 @@ -129,10 +126,8 @@
    1.26  											 IRootConsoleCommand *pHandler,
    1.27  											 bool version2)
    1.28  {
    1.29 -	if (sm_trie_retrieve(m_pCommands, cmd, NULL))
    1.30 -	{
    1.31 +	if (m_Commands.contains(cmd))
    1.32  		return false;
    1.33 -	}
    1.34  
    1.35  	/* Sort this into the menu */
    1.36  	List<ConsoleEntry *>::iterator iter = m_Menu.begin();
    1.37 @@ -148,7 +143,7 @@
    1.38  			pNew->description.assign(text);
    1.39  			pNew->version2 = version2;
    1.40  			pNew->cmd = pHandler;
    1.41 -			sm_trie_insert(m_pCommands, cmd, pNew);
    1.42 +			m_Commands.insert(cmd, pNew);
    1.43  			m_Menu.insert(iter, pNew);
    1.44  			inserted = true;
    1.45  			break;
    1.46 @@ -163,7 +158,7 @@
    1.47  		pNew->description.assign(text);
    1.48  		pNew->version2 = version2;
    1.49  		pNew->cmd = pHandler;
    1.50 -		sm_trie_insert(m_pCommands, cmd, pNew);
    1.51 +		m_Commands.insert(cmd, pNew);
    1.52  		m_Menu.push_back(pNew);
    1.53  	}
    1.54  
    1.55 @@ -172,7 +167,7 @@
    1.56  
    1.57  bool RootConsoleMenu::RemoveRootConsoleCommand(const char *cmd, IRootConsoleCommand *pHandler)
    1.58  {
    1.59 -	sm_trie_delete(m_pCommands, cmd);
    1.60 +	m_Commands.remove(cmd);
    1.61  
    1.62  	List<ConsoleEntry *>::iterator iter;
    1.63  	ConsoleEntry *pEntry;
    1.64 @@ -291,7 +286,7 @@
    1.65  		CCommandArgs ocmd(cmd);
    1.66  
    1.67  		ConsoleEntry *entry;
    1.68 -		if (sm_trie_retrieve(m_pCommands, cmdname, (void **)&entry))
    1.69 +		if (m_Commands.retrieve(cmdname, &entry))
    1.70  		{
    1.71  			if (entry->version2)
    1.72  			{
     2.1 --- a/core/sm_srvcmds.h	Sun Aug 25 12:16:07 2013 -0700
     2.2 +++ b/core/sm_srvcmds.h	Sun Aug 25 12:17:25 2013 -0700
     2.3 @@ -1,5 +1,5 @@
     2.4  /**
     2.5 - * vim: set ts=4 sw=4 :
     2.6 + * vim: set ts=4 sw=4 tw=99 noet :
     2.7   * =============================================================================
     2.8   * SourceMod
     2.9   * Copyright (C) 2004-2009 AlliedModders LLC.  All rights reserved.
    2.10 @@ -38,7 +38,7 @@
    2.11  #include <sh_list.h>
    2.12  #include <sh_string.h>
    2.13  #include <compat_wrappers.h>
    2.14 -#include "sm_trie.h"
    2.15 +#include <sm_namehashset.h>
    2.16  
    2.17  using namespace SourceMod;
    2.18  using namespace SourceHook;
    2.19 @@ -49,6 +49,11 @@
    2.20  	String description;
    2.21  	bool   version2;
    2.22  	IRootConsoleCommand *cmd;
    2.23 +
    2.24 +	static inline bool matches(const char *name, const ConsoleEntry *entry)
    2.25 +	{
    2.26 +		return strcmp(name, entry->command.c_str()) == 0;
    2.27 +	}
    2.28  };
    2.29  
    2.30  class RootConsoleMenu : 
    2.31 @@ -87,7 +92,7 @@
    2.32  	void GotRootCmd(const CCommand &cmd);
    2.33  private:
    2.34  	bool m_CfgExecDone;
    2.35 -	Trie *m_pCommands;
    2.36 +	NameHashSet<ConsoleEntry *> m_Commands;
    2.37  	List<ConsoleEntry *> m_Menu;
    2.38  };
    2.39