std::unordered_map::count is much slower than find

This commit is contained in:
Michael Cook (mackal) 2016-08-10 23:51:06 -04:00
parent 38d3f9b7c0
commit e90e141a79
2 changed files with 71 additions and 16 deletions

View File

@ -923,12 +923,18 @@ bool EntityList::MakeDoorSpawnPacket(EQApplicationPacket *app, Client *client)
Entity *EntityList::GetEntityMob(uint16 id)
{
return mob_list.count(id) ? mob_list.at(id) : nullptr;
auto it = mob_list.find(id);
if (it != mob_list.end())
return it->second;
return nullptr;
}
Entity *EntityList::GetEntityMerc(uint16 id)
{
return merc_list.count(id) ? merc_list.at(id) : nullptr;
auto it = merc_list.find(id);
if (it != merc_list.end())
return it->second;
return nullptr;
}
Entity *EntityList::GetEntityMob(const char *name)
@ -948,12 +954,18 @@ Entity *EntityList::GetEntityMob(const char *name)
Entity *EntityList::GetEntityDoor(uint16 id)
{
return door_list.count(id) ? door_list.at(id) : nullptr;
auto it = door_list.find(id);
if (it != door_list.end())
return it->second;
return nullptr;
}
Entity *EntityList::GetEntityCorpse(uint16 id)
{
return corpse_list.count(id) ? corpse_list.at(id) : nullptr;
auto it = corpse_list.find(id);
if (it != corpse_list.end())
return it->second;
return nullptr;
}
Entity *EntityList::GetEntityCorpse(const char *name)
@ -973,22 +985,34 @@ Entity *EntityList::GetEntityCorpse(const char *name)
Entity *EntityList::GetEntityTrap(uint16 id)
{
return trap_list.count(id) ? trap_list.at(id) : nullptr;
auto it = trap_list.find(id);
if (it != trap_list.end())
return it->second;
return nullptr;
}
Entity *EntityList::GetEntityObject(uint16 id)
{
return object_list.count(id) ? object_list.at(id) : nullptr;
auto it = object_list.find(id);
if (it != object_list.end())
return it->second;
return nullptr;
}
Entity *EntityList::GetEntityBeacon(uint16 id)
{
return beacon_list.count(id) ? beacon_list.at(id) : nullptr;
auto it = beacon_list.find(id);
if (it != beacon_list.end())
return it->second;
return nullptr;
}
Entity *EntityList::GetEntityEncounter(uint16 id)
{
return encounter_list.count(id) ? encounter_list.at(id) : nullptr;
auto it = encounter_list.find(id);
if (it != encounter_list.end())
return it->second;
return nullptr;
}
Entity *EntityList::GetID(uint16 get_id)
@ -1184,6 +1208,8 @@ void EntityList::ChannelMessage(Mob *from, uint8 chan_num, uint8 language,
void EntityList::ChannelMessageSend(Mob *to, uint8 chan_num, uint8 language, const char *message, ...)
{
if (!to->IsClient())
return;
va_list argptr;
char buffer[4096];
@ -1191,8 +1217,7 @@ void EntityList::ChannelMessageSend(Mob *to, uint8 chan_num, uint8 language, con
vsnprintf(buffer, 4096, message, argptr);
va_end(argptr);
if (client_list.count(to->GetID()))
client_list.at(to->GetID())->ChannelMessageSend(0, 0, chan_num, language, buffer);
to->CastToClient()->ChannelMessageSend(0, 0, chan_num, language, buffer);
}
void EntityList::SendZoneSpawns(Client *client)

View File

@ -148,14 +148,29 @@ public:
bool IsMobSpawnedByNpcTypeID(uint32 get_id);
Mob *GetTargetForVirus(Mob* spreader, int range);
inline NPC *GetNPCByID(uint16 id)
{ return npc_list.count(id) ? npc_list.at(id) : nullptr; }
{
auto it = npc_list.find(id);
if (it != npc_list.end())
return it->second;
return nullptr;
}
NPC *GetNPCByNPCTypeID(uint32 npc_id);
inline Merc *GetMercByID(uint16 id)
{ return merc_list.count(id) ? merc_list.at(id) : nullptr; }
{
auto it = merc_list.find(id);
if (it != merc_list.end())
return it->second;
return nullptr;
}
Client *GetClientByName(const char *name);
Client *GetClientByAccID(uint32 accid);
inline Client *GetClientByID(uint16 id)
{ return client_list.count(id) ? client_list.at(id) : nullptr; }
{
auto it = client_list.find(id);
if (it != client_list.end())
return it->second;
return nullptr;
}
Client *GetClientByCharID(uint32 iCharID);
Client *GetClientByWID(uint32 iWID);
Client *GetClient(uint32 ip, uint16 port);
@ -172,7 +187,12 @@ public:
Corpse *GetCorpseByOwner(Client* client);
Corpse *GetCorpseByOwnerWithinRange(Client* client, Mob* center, int range);
inline Corpse *GetCorpseByID(uint16 id)
{ return corpse_list.count(id) ? corpse_list.at(id) : nullptr; }
{
auto it = corpse_list.find(id);
if (it != corpse_list.end())
return it->second;
return nullptr;
}
Corpse *GetCorpseByDBID(uint32 dbid);
Corpse *GetCorpseByName(const char* name);
@ -181,10 +201,20 @@ public:
Client* FindCorpseDragger(uint16 CorpseID);
inline Object *GetObjectByID(uint16 id)
{ return object_list.count(id) ? object_list.at(id) : nullptr; }
{
auto it = object_list.find(id);
if (it != object_list.end())
return it->second;
return nullptr;
}
Object *GetObjectByDBID(uint32 id);
inline Doors *GetDoorsByID(uint16 id)
{ return door_list.count(id) ? door_list.at(id) : nullptr; }
{
auto it = door_list.find(id);
if (it != door_list.end())
return it->second;
return nullptr;
}
Doors *GetDoorsByDoorID(uint32 id);
Doors *GetDoorsByDBID(uint32 id);
void RemoveAllCorpsesByCharID(uint32 charid);