Switch smn_maplists off KTrie (bug 5884 part 4, r=ds).
Switch smn_maplists off KTrie (
bug 5884 part 4, r=ds).
1.1 --- a/core/logic/smn_maplists.cpp Sun Aug 25 11:59:46 2013 -0700
1.2 +++ b/core/logic/smn_maplists.cpp Sun Aug 25 11:59:47 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-2008 AlliedModders LLC. All rights reserved.
1.10 @@ -30,7 +30,7 @@
1.11 */
1.12
1.13 #include <sh_list.h>
1.14 -#include <sm_trie_tpl.h>
1.15 +#include <sm_namehashset.h>
1.16 #include "common_logic.h"
1.17 #include "CellArray.h"
1.18 #include <IGameHelpers.h>
1.19 @@ -50,6 +50,11 @@
1.20 time_t last_modified_time;
1.21 CellArray *pArray;
1.22 int serial;
1.23 +
1.24 + static inline bool matches(const char *key, const maplist_info_t *value)
1.25 + {
1.26 + return strcmp(value->name, key) == 0;
1.27 + }
1.28 };
1.29
1.30 #define MAPLIST_FLAG_MAPSFOLDER (1<<0) /**< On failure, use all maps in the maps folder. */
1.31 @@ -124,9 +129,9 @@
1.32 void AddOrUpdateDefault(const char *name, const char *file)
1.33 {
1.34 char path[PLATFORM_MAX_PATH];
1.35 - maplist_info_t *pMapList, **ppMapList;
1.36 + maplist_info_t *pMapList;
1.37
1.38 - if ((ppMapList = m_ListLookup.retrieve(name)) == NULL)
1.39 + if (!m_ListLookup.retrieve(name, &pMapList))
1.40 {
1.41 pMapList = new maplist_info_t;
1.42 pMapList->bIsCompat = true;
1.43 @@ -141,21 +146,15 @@
1.44 return;
1.45 }
1.46
1.47 - pMapList = *ppMapList;
1.48 -
1.49 /* Don't modify if it's from the config file */
1.50 if (!pMapList->bIsCompat)
1.51 - {
1.52 return;
1.53 - }
1.54
1.55 g_pSM->BuildPath(Path_Game, path, sizeof(path), "%s", file);
1.56
1.57 /* If the path matches, don't reset the serial/time */
1.58 if (strcmp(path, pMapList->path) == 0)
1.59 - {
1.60 return;
1.61 - }
1.62
1.63 smcore.strncopy(pMapList->path, path, sizeof(pMapList->path));
1.64 pMapList->bIsPath = true;
1.65 @@ -230,7 +229,7 @@
1.66 List<maplist_info_t *>::iterator iter = compat.begin();
1.67 while (iter != compat.end())
1.68 {
1.69 - if (m_ListLookup.retrieve((*iter)->name) != NULL)
1.70 + if (m_ListLookup.contains((*iter)->name))
1.71 {
1.72 /* The compatibility shim is no longer needed. */
1.73 delete (*iter)->pArray;
1.74 @@ -321,7 +320,7 @@
1.75 {
1.76 if (m_pCurMapList != NULL
1.77 && m_pCurMapList->path[0] != '\0'
1.78 - && m_ListLookup.retrieve(m_pCurMapList->name) == NULL)
1.79 + && !m_ListLookup.contains(m_pCurMapList->name))
1.80 {
1.81 m_ListLookup.insert(m_pCurMapList->name, m_pCurMapList);
1.82 m_MapLists.push_back(m_pCurMapList);
1.83 @@ -490,19 +489,13 @@
1.84 bool GetMapList(CellArray **ppArray, const char *name, int *pSerial)
1.85 {
1.86 time_t last_time;
1.87 - maplist_info_t *pMapList, **ppMapList;
1.88 + maplist_info_t *pMapList;
1.89
1.90 - if ((ppMapList = m_ListLookup.retrieve(name)) == NULL)
1.91 - {
1.92 + if (!m_ListLookup.retrieve(name, &pMapList))
1.93 return false;
1.94 - }
1.95 -
1.96 - pMapList = *ppMapList;
1.97
1.98 if (!pMapList->bIsPath)
1.99 - {
1.100 return GetMapList(ppArray, pMapList->path, pSerial);
1.101 - }
1.102
1.103 /* If it is a path, and the path is "*", assume all files must be used. */
1.104 if (strcmp(pMapList->path, "*") == 0)
1.105 @@ -598,7 +591,7 @@
1.106 char m_ConfigFile[PLATFORM_MAX_PATH];
1.107 time_t m_ConfigLastChanged;
1.108 ConVar *m_pMapCycleFile;
1.109 - KTrie<maplist_info_t *> m_ListLookup;
1.110 + NameHashSet<maplist_info_t *> m_ListLookup;
1.111 List<maplist_info_t *> m_MapLists;
1.112 MapListState m_CurState;
1.113 unsigned int m_IgnoreLevel;
2.1 --- a/public/sm_namehashset.h Sun Aug 25 11:59:46 2013 -0700
2.2 +++ b/public/sm_namehashset.h Sun Aug 25 11:59:47 2013 -0700
2.3 @@ -125,6 +125,13 @@
2.4 return table_.add(i, value);
2.5 }
2.6
2.7 + bool contains(const char *aKey)
2.8 + {
2.9 + CharsAndLength key(aKey);
2.10 + Result r = table_.find(aKey);
2.11 + return r.found();
2.12 + }
2.13 +
2.14 bool remove(const char *aKey)
2.15 {
2.16 CharsAndLength key(aKey);
2.17 @@ -135,6 +142,11 @@
2.18 return true;
2.19 }
2.20
2.21 + void clear()
2.22 + {
2.23 + table_.clear();
2.24 + }
2.25 +
2.26 private:
2.27 Internal table_;
2.28 };