Fix unnecessary ConVar cache misses (#1177)

Fixes #1166
This commit is contained in:
Michael 2020-02-11 08:39:19 +00:00 committed by GitHub
parent 1a71f4fbde
commit 8a5d0a58e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 8 deletions

View File

@ -41,7 +41,7 @@ ConVarManager g_ConVarManager;
const ParamType CONVARCHANGE_PARAMS[] = {Param_Cell, Param_String, Param_String};
typedef List<const ConVar *> ConVarList;
NameHashSet<ConVarInfo *> convar_cache;
NameHashSet<ConVarInfo *, ConVarInfo::ConVarPolicy> convar_cache;
class ConVarReentrancyGuard
{

View File

@ -64,14 +64,26 @@ struct ConVarInfo
ConVar *pVar; /**< The actual convar */
List<IConVarChangeListener *> changeListeners;
static inline bool matches(const char *name, const ConVarInfo *info)
struct ConVarPolicy
{
return strcmp(name, info->pVar->GetName()) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
static inline bool matches(const char *name, ConVarInfo *info)
{
const char *conVarChars = info->pVar->GetName();
ke::AString convarName = ke::AString(conVarChars).lowercase();
ke::AString input = ke::AString(name).lowercase();
return convarName == input;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
ke::AString original(key.chars());
ke::AString lower = original.lowercase();
return detail::CharsAndLength(lower.chars()).hash();
}
};
};
/**