Improve HasEntProp performance (#1908)

This commit is contained in:
Corey D 2023-03-30 15:40:30 +11:00 committed by GitHub
parent a28c3cac9b
commit bc6e920213
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 53 additions and 22 deletions

View File

@ -445,20 +445,25 @@ bool CHalfLife2::FindSendPropInfo(const char *classname, const char *offset, sm_
return false;
}
if (!pInfo->lookup.retrieve(offset, info))
{
sm_sendprop_info_t temp_info;
DataTableInfo::SendPropInfo temp;
if (!UTIL_FindInSendTable(pInfo->sc->m_pTable, offset, &temp_info, 0))
if (!pInfo->lookup.retrieve(offset, &temp))
{
bool found = UTIL_FindInSendTable(pInfo->sc->m_pTable, offset, &temp.info, 0);
temp.name = offset;
pInfo->lookup.insert(offset, temp);
if (found)
{
return false;
*info = temp.info;
}
pInfo->lookup.insert(offset, temp_info);
*info = temp_info;
return found;
}
return true;
*info = temp.info;
return info->prop != nullptr;
}
SendProp *CHalfLife2::FindInSendTable(const char *classname, const char *offset)
@ -492,15 +497,25 @@ bool CHalfLife2::FindDataMapInfo(datamap_t *pMap, const char *offset, sm_datatab
m_Maps.add(i, pMap, new DataMapCache());
DataMapCache *cache = i->value;
DataMapCacheInfo temp;
if (!cache->retrieve(offset, pDataTable))
if (!cache->retrieve(offset, &temp))
{
if (!UTIL_FindDataMapInfo(pMap, offset, pDataTable))
return false;
cache->insert(offset, *pDataTable);
bool found = UTIL_FindDataMapInfo(pMap, offset, &temp.info);
temp.name = offset;
cache->insert(offset, temp);
if (found)
{
*pDataTable = temp.info;
}
return found;
}
return true;
*pDataTable = temp.info;
return pDataTable->prop != nullptr;
}
void CHalfLife2::SetEdictStateChanged(edict_t *pEdict, unsigned short offset)

View File

@ -89,16 +89,24 @@ using namespace SourceMod;
struct DataTableInfo
{
struct SendPropPolicy
struct SendPropInfo
{
static inline bool matches(const char *name, const sm_sendprop_info_t &info)
static inline bool matches(const char *name, const SendPropInfo &info)
{
return strcmp(name, info.prop->GetName()) == 0;
return strcmp(name, info.name.c_str()) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
SendPropInfo()
: name(), info{nullptr, 0}
{
}
std::string name;
sm_sendprop_info_t info;
};
static inline bool matches(const char *name, const DataTableInfo *info)
@ -116,22 +124,30 @@ struct DataTableInfo
}
ServerClass *sc;
NameHashSet<sm_sendprop_info_t, SendPropPolicy> lookup;
NameHashSet<SendPropInfo> lookup;
};
struct DataMapCachePolicy
struct DataMapCacheInfo
{
static inline bool matches(const char *name, const sm_datatable_info_t &info)
static inline bool matches(const char *name, const DataMapCacheInfo &info)
{
return strcmp(name, info.prop->fieldName) == 0;
return strcmp(name, info.name.c_str()) == 0;
}
static inline uint32_t hash(const detail::CharsAndLength &key)
{
return key.hash();
}
DataMapCacheInfo()
: name(), info{nullptr, 0}
{
}
std::string name;
sm_datatable_info_t info;
};
typedef NameHashSet<sm_datatable_info_t, DataMapCachePolicy> DataMapCache;
typedef NameHashSet<DataMapCacheInfo> DataMapCache;
struct DelayedFakeCliCmd
{