Revert "Individualize NameHashSet Hashing & Revisit #709 (#740)"

This reverts commit 3803fbfe20.
This commit is contained in:
Michael Flaherty 2018-07-27 20:36:16 -07:00
parent 3803fbfe20
commit ece57df986
15 changed files with 40 additions and 99 deletions

View File

@ -43,7 +43,6 @@
#include <compat_wrappers.h>
#include "concmd_cleaner.h"
#include "PlayerManager.h"
#include <sm_stringhashmap.h>
using namespace SourceHook;
@ -68,10 +67,6 @@ struct ConVarInfo
{
return strcmp(name, info->pVar->GetName()) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
};
/**

View File

@ -77,10 +77,6 @@ struct EventHook
{
return strcmp(name, hook->name.chars()) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
};
enum EventHookMode

View File

@ -92,21 +92,13 @@ struct DataTableInfo
{
return strcmp(name, info.prop->GetName()) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
};
static inline bool matches(const char *name, const DataTableInfo *info)
{
return strcmp(name, info->sc->GetName()) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
DataTableInfo(ServerClass *sc)
: sc(sc)
{
@ -122,10 +114,6 @@ struct DataMapCachePolicy
{
return strcmp(name, info.prop->fieldName) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
};
typedef NameHashSet<sm_datatable_info_t, DataMapCachePolicy> DataMapCache;

View File

@ -82,10 +82,6 @@ struct AuthMethod
{
return strcmp(name, method->name.c_str()) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
};
struct UserAuth

View File

@ -72,10 +72,6 @@ public: //NameHashSet
{
return strcmp(key, value->m_File) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
private:
char m_File[PLATFORM_MAX_PATH];
char m_CurFile[PLATFORM_MAX_PATH];

View File

@ -110,10 +110,6 @@ struct QHandleType
{
return type->name && type->name->compare(key) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
};
typedef ke::Lambda<void(const char *)> HandleReporter;

View File

@ -36,7 +36,6 @@
#include <am-string.h>
#include <am-utility.h>
#include <am-refcounting.h>
#include <sm_stringhashmap.h>
#include "common_logic.h"
class CNativeOwner;
@ -94,10 +93,6 @@ struct Native : public ke::Refcounted<Native>
{
return strcmp(name, entry->name()) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
};

View File

@ -31,6 +31,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <ctype.h>
#include "PluginSys.h"
#include "ShareSys.h"
#include <ILibrarySys.h>
@ -46,6 +47,7 @@
#include "frame_tasks.h"
#include <amtl/am-string.h>
#include <amtl/am-linkedlist.h>
#include <amtl/am-uniqueptr.h>
#include <bridge/include/IVEngineServerBridge.h>
#include <bridge/include/CoreProvider.h>
@ -932,16 +934,38 @@ void CPluginManager::LoadPluginsFromDir(const char *basedir, const char *localpa
libsys->CloseDirectory(dir);
}
#if defined PLATFORM_WINDOWS || defined PLATFORM_APPLE
char *strdup_tolower(const char *input)
{
char *str = strdup(input);
for (char *c = str; *c; c++)
{
*c = tolower((unsigned char)*c);
}
return str;
}
#endif
LoadRes CPluginManager::LoadPlugin(CPlugin **aResult, const char *path, bool debug, PluginType type)
{
if (m_LoadingLocked)
return LoadRes_NeverLoad;
/* For windows & mac, we convert the path to lower-case in order to avoid duplicate plugin loading */
#if defined PLATFORM_WINDOWS || defined PLATFORM_APPLE
ke::UniquePtr<char> finalPath = ke::UniquePtr<char>(strdup_tolower(path));
#else
ke::UniquePtr<char> finalPath = ke::UniquePtr<char>(strdup(path));
#endif
/**
* Does this plugin already exist?
*/
CPlugin *pPlugin;
if (m_LoadLookup.retrieve(path, &pPlugin))
if (m_LoadLookup.retrieve(finalPath.get(), &pPlugin))
{
/* Check to see if we should try reloading it */
if (pPlugin->GetStatus() == Plugin_BadLoad
@ -954,11 +978,12 @@ LoadRes CPluginManager::LoadPlugin(CPlugin **aResult, const char *path, bool deb
{
if (aResult)
*aResult = pPlugin;
return LoadRes_AlreadyLoaded;
}
}
CPlugin *plugin = CompileAndPrep(path);
CPlugin *plugin = CompileAndPrep(finalPath.get());
// Assign our outparam so we can return early. It must be set.
*aResult = plugin;
@ -2391,4 +2416,4 @@ static OldPluginAPI sOldPluginAPI;
IPluginManager *CPluginManager::GetOldAPI()
{
return &sOldPluginAPI;
}
}

View File

@ -143,6 +143,11 @@ public:
*/
static CPlugin *Create(const char *file);
static inline bool matches(const char *file, const CPlugin *plugin)
{
return strcmp(plugin->m_filename, file) == 0;
}
public:
// Evicts the plugin from memory and sets an error state.
void EvictWithError(PluginStatus status, const char *error_fmt, ...);
@ -478,36 +483,7 @@ private:
typedef decltype(m_listeners)::iterator ListenerIter;
typedef decltype(m_plugins)::iterator PluginIter;
struct CPluginPolicy
{
static inline uint32_t hash(const detail::CharsAndLength &key)
{
/* For windows & mac, we convert the path to lower-case in order to avoid duplicate plugin loading */
#if defined PLATFORM_WINDOWS || defined PLATFORM_APPLE
ke::AString original(key.chars());
ke::AString lower = original.lowercase();
return detail::CharsAndLength(lower.chars()).hash();
#else
return key.hash();
#endif
}
static inline bool matches(const char *file, const CPlugin *plugin)
{
const char *pluginFileChars = const_cast<CPlugin*>(plugin)->GetFilename();
#if defined PLATFORM_WINDOWS || defined PLATFORM_APPLE
ke::AString pluginFile = ke::AString(pluginFileChars).lowercase();
ke::AString input = ke::AString(file).lowercase();
return pluginFile == input;
#else
return strcmp(pluginFileChars, file) == 0;
#endif
}
};
NameHashSet<CPlugin *, CPluginPolicy> m_LoadLookup;
NameHashSet<CPlugin *> m_LoadLookup;
bool m_AllPluginsLoaded;
IdentityToken_t *m_MyIdent;

View File

@ -46,10 +46,6 @@ struct ConsoleEntry
{
return strcmp(name, entry->command.c_str()) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
};
class RootConsoleMenu :

View File

@ -58,10 +58,6 @@ struct maplist_info_t
{
return strcmp(value->name, key) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
};
#define MAPLIST_FLAG_MAPSFOLDER (1<<0) /**< On failure, use all maps in the maps folder. */

View File

@ -184,10 +184,6 @@ private:
{
return strcmp(name, base->GetName()) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
};
NameHashSet<ConCommandBase *, ConCommandPolicy> m_CmdFlags;
} s_CommandFlagsHelper;

View File

@ -96,10 +96,6 @@ struct Cookie
{
return strcmp(name, cookie->name) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
};
class CookieManager : public IClientListener, public IPluginsListener

View File

@ -77,10 +77,6 @@ struct topmenu_object_t
{
return strcmp(name, topmenu->name) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
};
struct topmenu_category_t

View File

@ -48,12 +48,10 @@
namespace SourceMod
{
// The HashPolicy type must have these methods:
// The HashPolicy type must have this method:
// static bool matches(const char *key, const T &value);
// static uint32_t hash(const CharsAndLength &key);
//
// Depending on what lookup types are used, and how hashing should be done.
// Most of the time, key hashing will just call the key's hash() method.
// Depending on what lookup types are used.
//
// If these members are available on T, then the HashPolicy type can be left
// default. It is okay to use |T *|, the functions will still be looked up
@ -71,7 +69,7 @@ class NameHashSet : public ke::SystemAllocatorPolicy
static uint32_t hash(const CharsAndLength &key)
{
return KeyPolicyType::hash(key);
return key.hash();
}
static bool matches(const CharsAndLength &key, const KeyType &value)
@ -87,9 +85,9 @@ class NameHashSet : public ke::SystemAllocatorPolicy
{
typedef KeyType *Payload;
static uint32_t hash(const CharsAndLength &key)
static uint32_t hash(const detail::CharsAndLength &key)
{
return KeyType::hash(key);
return key.hash();
}
static bool matches(const CharsAndLength &key, const KeyType *value)