From b474dc44bb6323430a84fc17c1ec046f9919a101 Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Thu, 11 Apr 2024 11:02:42 +0800 Subject: [PATCH] Performance optim --- src/PlayerbotFactory.cpp | 16 ++++++++-------- src/PlayerbotMgr.cpp | 4 ++-- src/strategy/NamedObjectContext.h | 17 +++++++++-------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/PlayerbotFactory.cpp b/src/PlayerbotFactory.cpp index 88a4d1dc..ddcbef79 100644 --- a/src/PlayerbotFactory.cpp +++ b/src/PlayerbotFactory.cpp @@ -605,7 +605,7 @@ void PlayerbotFactory::InitPetTalents() return; } pet->resetTalents(); - std::map > spells; + std::unordered_map > spells; for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i) { TalentEntry const *talentInfo = sTalentStore.LookupEntry(i); @@ -625,7 +625,7 @@ void PlayerbotFactory::InitPetTalents() uint32 maxTalentPoints = pet->GetMaxTalentPointsForLevel(pet->GetLevel()); int row = 0; // LOG_INFO("playerbots", "{} learning, max talent points: {}, cur: {}", bot->GetName().c_str(), maxTalentPoints, curTalentPoints); - for (std::map >::iterator i = spells.begin(); i != spells.end(); ++i, ++row) + for (auto i = spells.begin(); i != spells.end(); ++i, ++row) { std::vector &spells_row = i->second; if (spells_row.empty()) @@ -893,7 +893,7 @@ void PlayerbotFactory::InitTalentsBySpecNo(Player* bot, int specNo, bool reset) uint32 cls = bot->getClass(); int startLevel = bot->GetLevel(); uint32 classMask = bot->getClassMask(); - std::map > spells_row; + std::unordered_map > spells_row; for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i) { TalentEntry const *talentInfo = sTalentStore.LookupEntry(i); @@ -954,7 +954,7 @@ void PlayerbotFactory::InitTalentsByParsedSpecLink(Player* bot, std::vectorresetTalents(true); } uint32 classMask = bot->getClassMask(); - std::map > spells_row; + std::unordered_map > spells_row; for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i) { TalentEntry const *talentInfo = sTalentStore.LookupEntry(i); @@ -2248,7 +2248,7 @@ void PlayerbotFactory::InitSpecialSpells() void PlayerbotFactory::InitTalents(uint32 specNo) { uint32 classMask = bot->getClassMask(); - std::map > spells; + std::unordered_map > spells; for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i) { TalentEntry const *talentInfo = sTalentStore.LookupEntry(i); @@ -2266,7 +2266,7 @@ void PlayerbotFactory::InitTalents(uint32 specNo) } uint32 freePoints = bot->GetFreeTalentPoints(); - for (std::map >::iterator i = spells.begin(); i != spells.end(); ++i) + for (auto i = spells.begin(); i != spells.end(); ++i) { std::vector &spells_row = i->second; if (spells_row.empty()) @@ -2308,7 +2308,7 @@ void PlayerbotFactory::InitTalentsByTemplate(uint32 specTab) int startLevel = bot->GetLevel(); uint32 specIndex = sPlayerbotAIConfig->randomClassSpecIndex[cls][specTab]; uint32 classMask = bot->getClassMask(); - std::map > spells_row; + std::unordered_map > spells_row; for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i) { TalentEntry const *talentInfo = sTalentStore.LookupEntry(i); @@ -2648,7 +2648,7 @@ void PlayerbotFactory::InitFood() if (sPlayerbotAIConfig->freeFood) { return; } - std::map > items; + std::unordered_map > items; ItemTemplateContainer const* itemTemplateContainer = sObjectMgr->GetItemTemplateStore(); for (ItemTemplateContainer::const_iterator i = itemTemplateContainer->begin(); i != itemTemplateContainer->end(); ++i) { diff --git a/src/PlayerbotMgr.cpp b/src/PlayerbotMgr.cpp index 49dbf467..325ebacc 100644 --- a/src/PlayerbotMgr.cpp +++ b/src/PlayerbotMgr.cpp @@ -900,7 +900,7 @@ std::vector PlayerbotHolder::HandlePlayerbotCommand(char const* arg std::string const cmdStr = cmd; - std::set bots; + std::unordered_set bots; if (charnameStr == "*" && master) { Group* group = master->GetGroup(); @@ -958,7 +958,7 @@ std::vector PlayerbotHolder::HandlePlayerbotCommand(char const* arg } } - for (std::set::iterator i = bots.begin(); i != bots.end(); ++i) + for (auto i = bots.begin(); i != bots.end(); ++i) { std::string const bot = *i; diff --git a/src/strategy/NamedObjectContext.h b/src/strategy/NamedObjectContext.h index a288a59c..d621ca93 100644 --- a/src/strategy/NamedObjectContext.h +++ b/src/strategy/NamedObjectContext.h @@ -7,8 +7,9 @@ #include "Common.h" -#include +#include #include +#include #include #include @@ -46,7 +47,7 @@ class NamedObjectFactory { protected: typedef T*(*ActionCreator)(PlayerbotAI* botAI); - std::map creators; + std::unordered_map creators; public: T* create(std::string name, PlayerbotAI* botAI) @@ -77,7 +78,7 @@ class NamedObjectFactory std::set supports() { std::set keys; - for (typename std::map::iterator it = creators.begin(); it != creators.end(); it++) + for (typename std::unordered_map::iterator it = creators.begin(); it != creators.end(); it++) keys.insert(it->first); return keys; @@ -106,7 +107,7 @@ class NamedObjectContext : public NamedObjectFactory void Clear() { - for (typename std::map::iterator i = created.begin(); i != created.end(); i++) + for (typename std::unordered_map::iterator i = created.begin(); i != created.end(); i++) { if (i->second) delete i->second; @@ -117,7 +118,7 @@ class NamedObjectContext : public NamedObjectFactory void Update() { - for (typename std::map::iterator i = created.begin(); i != created.end(); i++) + for (typename std::unordered_map::iterator i = created.begin(); i != created.end(); i++) { if (i->second) i->second->Update(); @@ -126,7 +127,7 @@ class NamedObjectContext : public NamedObjectFactory void Reset() { - for (typename std::map::iterator i = created.begin(); i != created.end(); i++) + for (typename std::unordered_map::iterator i = created.begin(); i != created.end(); i++) { if (i->second) i->second->Reset(); @@ -139,14 +140,14 @@ class NamedObjectContext : public NamedObjectFactory std::set GetCreated() { std::set keys; - for (typename std::map::iterator it = created.begin(); it != created.end(); it++) + for (typename std::unordered_map::iterator it = created.begin(); it != created.end(); it++) keys.insert(it->first); return keys; } protected: - std::map created; + std::unordered_map created; bool shared; bool supportsSiblings; };