From 51dc097266bc6da271c267884b672d72be9ab2cd Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sun, 25 Aug 2013 12:20:38 -0700 Subject: [PATCH] Switch TopMenus off KTrie (bug 5884 part 16, r=ds). --- extensions/topmenus/TopMenu.cpp | 34 +++++++-------------------------- extensions/topmenus/TopMenu.h | 11 ++++++++--- public/sm_namehashset.h | 5 +++++ 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/extensions/topmenus/TopMenu.cpp b/extensions/topmenus/TopMenu.cpp index 0a514856..8c14f7b9 100644 --- a/extensions/topmenus/TopMenu.cpp +++ b/extensions/topmenus/TopMenu.cpp @@ -1,5 +1,5 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 tw=99 noet : * ============================================================================= * SourceMod TopMenus Extension * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. @@ -169,7 +169,7 @@ unsigned int TopMenu::AddToMenu2(const char *name, { return 0; } - else if (m_ObjLookup.retrieve(name) != NULL) + else if (m_ObjLookup.contains(name)) { return 0; } @@ -483,13 +483,8 @@ void TopMenu::OnMenuSelect2(IBaseMenu *menu, int client, unsigned int item, unsi topmenu_object_t *obj; topmenu_player_t *pClient = &m_clients[client]; - topmenu_object_t **pObject = m_ObjLookup.retrieve(item_name); - if (pObject == NULL) - { + if (!m_ObjLookup.retrieve(item_name, &obj)) return; - } - - obj = *pObject; /* We now have the object... what do we do with it? */ if (obj->type == TopMenuObject_Category) @@ -532,13 +527,8 @@ void TopMenu::OnMenuDrawItem(IBaseMenu *menu, int client, unsigned int item, uns } topmenu_object_t *obj; - topmenu_object_t **pObject = m_ObjLookup.retrieve(item_name); - if (pObject == NULL) - { + if (!m_ObjLookup.retrieve(item_name, &obj)) return; - } - - obj = *pObject; /* If the category has nothing to display, disable it. */ if (obj->type == TopMenuObject_Category) @@ -583,13 +573,8 @@ unsigned int TopMenu::OnMenuDisplayItem(IBaseMenu *menu, } topmenu_object_t *obj; - topmenu_object_t **pObject = m_ObjLookup.retrieve(item_name); - if (pObject == NULL) - { + if (!m_ObjLookup.retrieve(item_name, &obj)) return 0; - } - - obj = *pObject; /* Ask the object to render the text for this client */ char renderbuf[64]; @@ -1134,17 +1119,12 @@ SMCResult TopMenu::ReadSMC_LeavingSection(const SMCStates *states) unsigned int TopMenu::FindCategory(const char *name) { - topmenu_object_t **p_obj = m_ObjLookup.retrieve(name); - if (!p_obj) - { + topmenu_object_t *obj; + if (!m_ObjLookup.retrieve(name, &obj)) return 0; - } - topmenu_object_t *obj = *p_obj; if (obj->type != TopMenuObject_Category) - { return 0; - } return obj->object_id; } diff --git a/extensions/topmenus/TopMenu.h b/extensions/topmenus/TopMenu.h index a20695c9..2a41ff90 100644 --- a/extensions/topmenus/TopMenu.h +++ b/extensions/topmenus/TopMenu.h @@ -1,5 +1,5 @@ /** - * vim: set ts=4 : + * vim: set ts=4 sw=4 tw=99 noet : * ============================================================================= * SourceMod TopMenus Extension * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. @@ -34,10 +34,10 @@ #include #include -#include #include #include "smsdk_ext.h" #include "sm_memtable.h" +#include using namespace SourceHook; using namespace SourceMod; @@ -72,6 +72,11 @@ struct topmenu_object_t bool is_free; /** Free or not? */ char info[255]; /** Info string */ unsigned int cat_id; /** Set if a category */ + + static inline bool matches(const char *name, const topmenu_object_t *topmenu) + { + return strcmp(name, topmenu->name) == 0; + } }; struct topmenu_category_t @@ -173,7 +178,7 @@ private: CVector m_UnsortedCats; /* Un-sorted categories */ CVector m_Categories; /* Category array */ CVector m_Objects; /* Object array */ - KTrie m_ObjLookup; /* Object lookup trie */ + NameHashSet m_ObjLookup; /* Object lookup trie */ unsigned int m_SerialNo; /* Serial number for updating */ ITopMenuObjectCallbacks *m_pTitle; /* Title callbacks */ int m_max_clients; /* Maximum number of clients */ diff --git a/public/sm_namehashset.h b/public/sm_namehashset.h index 1c40d94b..2ff1cb11 100644 --- a/public/sm_namehashset.h +++ b/public/sm_namehashset.h @@ -148,6 +148,11 @@ public: table_.clear(); } + size_t mem_usage() const + { + return table_.estimateMemoryUse(); + } + iterator iter() { return iterator(&table_);