Switch TopMenus off KTrie (bug 5884 part 16, r=ds).
authorDavid Anderson <dvander@alliedmods.net>
Sun Aug 25 12:20:38 2013 -0700 (2013-08-25)
changeset 4078483b617ef4f2
parent 4077 01e607ae37f0
child 4079 fc78b3dddc36
Switch TopMenus off KTrie (bug 5884 part 16, r=ds).
extensions/topmenus/TopMenu.cpp
extensions/topmenus/TopMenu.h
public/sm_namehashset.h
     1.1 --- a/extensions/topmenus/TopMenu.cpp	Sun Aug 25 12:19:10 2013 -0700
     1.2 +++ b/extensions/topmenus/TopMenu.cpp	Sun Aug 25 12:20:38 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 TopMenus Extension
     1.9   * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
    1.10 @@ -169,7 +169,7 @@
    1.11  	{
    1.12  		return 0;
    1.13  	}
    1.14 -	else if (m_ObjLookup.retrieve(name) != NULL)
    1.15 +	else if (m_ObjLookup.contains(name))
    1.16  	{
    1.17  		return 0;
    1.18  	}
    1.19 @@ -483,13 +483,8 @@
    1.20  
    1.21  	topmenu_object_t *obj;
    1.22  	topmenu_player_t *pClient = &m_clients[client];
    1.23 -	topmenu_object_t **pObject = m_ObjLookup.retrieve(item_name);
    1.24 -	if (pObject == NULL)
    1.25 -	{
    1.26 +	if (!m_ObjLookup.retrieve(item_name, &obj))
    1.27  		return;
    1.28 -	}
    1.29 -
    1.30 -	obj = *pObject;
    1.31  
    1.32  	/* We now have the object... what do we do with it? */
    1.33  	if (obj->type == TopMenuObject_Category)
    1.34 @@ -532,13 +527,8 @@
    1.35  	}
    1.36  
    1.37  	topmenu_object_t *obj;
    1.38 -	topmenu_object_t **pObject = m_ObjLookup.retrieve(item_name);
    1.39 -	if (pObject == NULL)
    1.40 -	{
    1.41 +	if (!m_ObjLookup.retrieve(item_name, &obj))
    1.42  		return;
    1.43 -	}
    1.44 -
    1.45 -	obj = *pObject;
    1.46  
    1.47  	/* If the category has nothing to display, disable it. */
    1.48  	if (obj->type == TopMenuObject_Category)
    1.49 @@ -583,13 +573,8 @@
    1.50  	}
    1.51  
    1.52  	topmenu_object_t *obj;
    1.53 -	topmenu_object_t **pObject = m_ObjLookup.retrieve(item_name);
    1.54 -	if (pObject == NULL)
    1.55 -	{
    1.56 +	if (!m_ObjLookup.retrieve(item_name, &obj))
    1.57  		return 0;
    1.58 -	}
    1.59 -
    1.60 -	obj = *pObject;
    1.61  
    1.62  	/* Ask the object to render the text for this client */
    1.63  	char renderbuf[64];
    1.64 @@ -1134,17 +1119,12 @@
    1.65  
    1.66  unsigned int TopMenu::FindCategory(const char *name)
    1.67  {
    1.68 -	topmenu_object_t **p_obj = m_ObjLookup.retrieve(name);
    1.69 -	if (!p_obj)
    1.70 -	{
    1.71 +	topmenu_object_t *obj;
    1.72 +	if (!m_ObjLookup.retrieve(name, &obj))
    1.73  		return 0;
    1.74 -	}
    1.75  
    1.76 -	topmenu_object_t *obj = *p_obj;
    1.77  	if (obj->type != TopMenuObject_Category)
    1.78 -	{
    1.79  		return 0;
    1.80 -	}
    1.81  
    1.82  	return obj->object_id;
    1.83  }
     2.1 --- a/extensions/topmenus/TopMenu.h	Sun Aug 25 12:19:10 2013 -0700
     2.2 +++ b/extensions/topmenus/TopMenu.h	Sun Aug 25 12:20:38 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 TopMenus Extension
     2.9   * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
    2.10 @@ -34,10 +34,10 @@
    2.11  
    2.12  #include <sh_list.h>
    2.13  #include <sh_vector.h>
    2.14 -#include <sm_trie_tpl.h>
    2.15  #include <ITopMenus.h>
    2.16  #include "smsdk_ext.h"
    2.17  #include "sm_memtable.h"
    2.18 +#include <sm_namehashset.h>
    2.19  
    2.20  using namespace SourceHook;
    2.21  using namespace SourceMod;
    2.22 @@ -72,6 +72,11 @@
    2.23  	bool is_free;						/** Free or not? */
    2.24  	char info[255];						/** Info string */
    2.25  	unsigned int cat_id;				/** Set if a category */
    2.26 +
    2.27 +	static inline bool matches(const char *name, const topmenu_object_t *topmenu)
    2.28 +	{
    2.29 +		return strcmp(name, topmenu->name) == 0;
    2.30 +	}
    2.31  };
    2.32  
    2.33  struct topmenu_category_t
    2.34 @@ -173,7 +178,7 @@
    2.35  	CVector<unsigned int> m_UnsortedCats;	/* Un-sorted categories */
    2.36  	CVector<topmenu_category_t *> m_Categories; /* Category array */
    2.37  	CVector<topmenu_object_t *> m_Objects;	/* Object array */
    2.38 -	KTrie<topmenu_object_t *> m_ObjLookup;	/* Object lookup trie */
    2.39 +	NameHashSet<topmenu_object_t *> m_ObjLookup; /* Object lookup trie */
    2.40  	unsigned int m_SerialNo;				/* Serial number for updating */
    2.41  	ITopMenuObjectCallbacks *m_pTitle;		/* Title callbacks */
    2.42  	int m_max_clients;						/* Maximum number of clients */
     3.1 --- a/public/sm_namehashset.h	Sun Aug 25 12:19:10 2013 -0700
     3.2 +++ b/public/sm_namehashset.h	Sun Aug 25 12:20:38 2013 -0700
     3.3 @@ -148,6 +148,11 @@
     3.4  		table_.clear();
     3.5  	}
     3.6  
     3.7 +	size_t mem_usage() const
     3.8 +	{
     3.9 +		return table_.estimateMemoryUse();
    3.10 +	}
    3.11 +
    3.12  	iterator iter()
    3.13  	{
    3.14  		return iterator(&table_);