Switch ShareSys off KTrie (bug 5884 part 5, r=ds).
authorDavid Anderson <dvander@alliedmods.net>
Sun Aug 25 11:59:47 2013 -0700 (2013-08-25)
changeset 4067cc438da4a30c
parent 4066 c055944bdfd6
child 4068 5a6151072b18
Switch ShareSys off KTrie (bug 5884 part 5, r=ds).
core/logic/ShareSys.cpp
core/logic/ShareSys.h
     1.1 --- a/core/logic/ShareSys.cpp	Sun Aug 25 11:59:47 2013 -0700
     1.2 +++ b/core/logic/ShareSys.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 @@ -287,14 +287,10 @@
    1.11  
    1.12  NativeEntry *ShareSystem::FindNative(const char *name)
    1.13  {
    1.14 -	NativeEntry **ppEntry;
    1.15 -
    1.16 -	if ((ppEntry = m_NtvCache.retrieve(name)) == NULL)
    1.17 -	{
    1.18 +	NativeEntry *entry;
    1.19 +	if (!m_NtvCache.retrieve(name, &entry))
    1.20  		return NULL;
    1.21 -	}
    1.22 -
    1.23 -	return *ppEntry;
    1.24 +	return entry;
    1.25  }
    1.26  
    1.27  void ShareSystem::BindNativesToPlugin(CPlugin *pPlugin, bool bCoreOnly)
    1.28 @@ -531,7 +527,7 @@
    1.29  void ShareSystem::AddCapabilityProvider(IExtension *myself, IFeatureProvider *provider,
    1.30  		                                const char *name)
    1.31  {
    1.32 -	if (m_caps.retrieve(name) != NULL)
    1.33 +	if (m_caps.contains(name))
    1.34  		return;
    1.35  
    1.36  	Capability cap;
    1.37 @@ -544,14 +540,13 @@
    1.38  void ShareSystem::DropCapabilityProvider(IExtension *myself, IFeatureProvider *provider,
    1.39  		                                 const char *name)
    1.40  {
    1.41 -	Capability *pCap = m_caps.retrieve(name);
    1.42 -	if (pCap == NULL)
    1.43 +	StringHashMap<Capability>::Result r = m_caps.find(name);
    1.44 +	if (!r.found())
    1.45 +		return;
    1.46 +	if (r->value.ext != myself || r->value.provider != provider)
    1.47  		return;
    1.48  
    1.49 -	if (pCap->ext != myself || pCap->provider != provider)
    1.50 -		return;
    1.51 -
    1.52 -	m_caps.remove(name);
    1.53 +	m_caps.remove(r);
    1.54  }
    1.55  
    1.56  FeatureStatus ShareSystem::TestFeature(IPluginRuntime *pRuntime, FeatureType feature, 
    1.57 @@ -603,9 +598,9 @@
    1.58  
    1.59  FeatureStatus ShareSystem::TestCap(const char *name)
    1.60  {
    1.61 -	Capability *cap = m_caps.retrieve(name);
    1.62 -	if (cap == NULL)
    1.63 +	StringHashMap<Capability>::Result r = m_caps.find(name);
    1.64 +	if (!r.found())
    1.65  		return FeatureStatus_Unknown;
    1.66  
    1.67 -	return cap->provider->GetFeatureStatus(FeatureType_Capability, name);
    1.68 +	return r->value.provider->GetFeatureStatus(FeatureType_Capability, name);
    1.69  }
     2.1 --- a/core/logic/ShareSys.h	Sun Aug 25 11:59:47 2013 -0700
     2.2 +++ b/core/logic/ShareSys.h	Sun Aug 25 11:59:47 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
     2.9   * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
    2.10 @@ -35,7 +35,8 @@
    2.11  #include <IShareSys.h>
    2.12  #include <IHandleSys.h>
    2.13  #include <sh_list.h>
    2.14 -#include <sm_trie_tpl.h>
    2.15 +#include <sm_stringhashmap.h>
    2.16 +#include <sm_namehashset.h>
    2.17  #include "common_logic.h"
    2.18  
    2.19  using namespace SourceHook;
    2.20 @@ -84,6 +85,11 @@
    2.21  	const char *name;
    2.22  	ReplaceNative replacement;
    2.23  	FakeNative *fake;
    2.24 +
    2.25 +	static inline bool matches(const char *name, const NativeEntry *entry)
    2.26 +	{
    2.27 +		return strcmp(name, entry->name) == 0;
    2.28 +	}
    2.29  };
    2.30  
    2.31  struct Capability
    2.32 @@ -154,8 +160,8 @@
    2.33  	IdentityToken_t m_IdentRoot;
    2.34  	HandleType_t m_IfaceType;
    2.35  	IdentityType_t m_CoreType;
    2.36 -	KTrie<NativeEntry *> m_NtvCache;
    2.37 -	KTrie<Capability> m_caps;
    2.38 +	NameHashSet<NativeEntry *> m_NtvCache;
    2.39 +	StringHashMap<Capability> m_caps;
    2.40  };
    2.41  
    2.42  extern ShareSystem g_ShareSys;