Improve HasEntProp performance (#1908)
This commit is contained in:
parent
a28c3cac9b
commit
bc6e920213
@ -445,20 +445,25 @@ bool CHalfLife2::FindSendPropInfo(const char *classname, const char *offset, sm_
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!pInfo->lookup.retrieve(offset, info))
|
DataTableInfo::SendPropInfo temp;
|
||||||
{
|
|
||||||
sm_sendprop_info_t temp_info;
|
|
||||||
|
|
||||||
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);
|
return found;
|
||||||
*info = temp_info;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
*info = temp.info;
|
||||||
|
return info->prop != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
SendProp *CHalfLife2::FindInSendTable(const char *classname, const char *offset)
|
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());
|
m_Maps.add(i, pMap, new DataMapCache());
|
||||||
|
|
||||||
DataMapCache *cache = i->value;
|
DataMapCache *cache = i->value;
|
||||||
|
DataMapCacheInfo temp;
|
||||||
|
|
||||||
if (!cache->retrieve(offset, pDataTable))
|
if (!cache->retrieve(offset, &temp))
|
||||||
{
|
{
|
||||||
if (!UTIL_FindDataMapInfo(pMap, offset, pDataTable))
|
bool found = UTIL_FindDataMapInfo(pMap, offset, &temp.info);
|
||||||
return false;
|
temp.name = offset;
|
||||||
cache->insert(offset, *pDataTable);
|
|
||||||
|
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)
|
void CHalfLife2::SetEdictStateChanged(edict_t *pEdict, unsigned short offset)
|
||||||
|
@ -89,16 +89,24 @@ using namespace SourceMod;
|
|||||||
|
|
||||||
struct DataTableInfo
|
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)
|
static inline uint32_t hash(const detail::CharsAndLength &key)
|
||||||
{
|
{
|
||||||
return key.hash();
|
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)
|
static inline bool matches(const char *name, const DataTableInfo *info)
|
||||||
@ -116,22 +124,30 @@ struct DataTableInfo
|
|||||||
}
|
}
|
||||||
|
|
||||||
ServerClass *sc;
|
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)
|
static inline uint32_t hash(const detail::CharsAndLength &key)
|
||||||
{
|
{
|
||||||
return key.hash();
|
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
|
struct DelayedFakeCliCmd
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user