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
+35 -10
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)