aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorleak <leakzx@googlemail.com>2011-03-11 00:18:18 +0100
committerleak <leakzx@googlemail.com>2011-03-11 00:18:49 +0100
commit4f892bbba11e6737f5a0461af5d0ded6cb313a51 (patch)
tree80e71aeb8b26038b50a01d51b6d066ccf2f947f9 /src
parent0aa015d8975a203267183eaa6e73ac8ae3b4c185 (diff)
Core/ObjectMgr: Use a map rather than a vector for indexing guilds by their guid (might contain large gaps).
Diffstat (limited to 'src')
-rwxr-xr-xsrc/server/game/Globals/ObjectMgr.cpp44
-rwxr-xr-xsrc/server/game/Globals/ObjectMgr.h2
2 files changed, 16 insertions, 30 deletions
diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp
index 964c9aae9d9..b12319f6564 100755
--- a/src/server/game/Globals/ObjectMgr.cpp
+++ b/src/server/game/Globals/ObjectMgr.cpp
@@ -298,8 +298,7 @@ ObjectMgr::~ObjectMgr()
delete *itr;
for (GuildMap::iterator itr = mGuildMap.begin(); itr != mGuildMap.end(); ++itr)
- if (*itr)
- delete *itr;
+ delete itr->second;
for (ArenaTeamMap::iterator itr = mArenaTeamMap.begin(); itr != mArenaTeamMap.end(); ++itr)
delete itr->second;
@@ -332,9 +331,10 @@ Group* ObjectMgr::GetGroupByStorageId(uint32 storageId) const
// Guild collection
Guild* ObjectMgr::GetGuildById(uint32 guildId) const
{
- // Make sure given index exists in collection
- if (guildId < uint32(mGuildMap.size()))
- return mGuildMap[guildId];
+ GuildMap::const_iterator itr = mGuildMap.find(guildId);
+ if (itr != mGuildMap.end())
+ return itr->second;
+
return NULL;
}
@@ -344,13 +344,10 @@ Guild* ObjectMgr::GetGuildByName(const std::string& guildname) const
std::transform(search.begin(), search.end(), search.begin(), ::toupper);
for (GuildMap::const_iterator itr = mGuildMap.begin(); itr != mGuildMap.end(); ++itr)
{
- if (*itr)
- {
- std::string gname = (*itr)->GetName();
- std::transform(gname.begin(), gname.end(), gname.begin(), ::toupper);
- if (search == gname)
- return *itr;
- }
+ std::string gname = itr->second->GetName();
+ std::transform(gname.begin(), gname.end(), gname.begin(), ::toupper);
+ if (search == gname)
+ return itr->second;
}
return NULL;
}
@@ -365,29 +362,20 @@ std::string ObjectMgr::GetGuildNameById(uint32 guildId) const
Guild* ObjectMgr::GetGuildByLeader(const uint64 &guid) const
{
for (GuildMap::const_iterator itr = mGuildMap.begin(); itr != mGuildMap.end(); ++itr)
- if ((*itr) && (*itr)->GetLeaderGUID() == guid)
- return *itr;
+ if (itr->second->GetLeaderGUID() == guid)
+ return itr->second;
return NULL;
}
-void ObjectMgr::AddGuild(Guild* pGuild)
+void ObjectMgr::AddGuild(Guild* guild)
{
- uint32 guildId = pGuild->GetId();
- // Allocate space if necessary
- if (guildId >= uint32(mGuildMap.size()))
- // Reserve a bit more space than necessary.
- // 16 is intentional and it will allow creation of next 16 guilds happen
- // without reallocation.
- mGuildMap.resize(guildId + 16);
- mGuildMap[guildId] = pGuild;
+ mGuildMap[guild->GetId()] = guild;
}
void ObjectMgr::RemoveGuild(uint32 guildId)
{
- // Make sure given index exists
- if (guildId < uint32(mGuildMap.size()))
- mGuildMap[guildId] = NULL;
+ mGuildMap.erase(guildId);
}
// Arena teams collection
@@ -3676,8 +3664,6 @@ void ObjectMgr::LoadGuilds()
}
else
{
- mGuildMap.resize(m_guildId, NULL); // Reserve space and initialize storage for loading guilds //TODOLEAK: fix this shit
-
uint32 count = 0;
do
{
@@ -3968,7 +3954,7 @@ void ObjectMgr::LoadGuilds()
for (GuildMap::iterator itr = mGuildMap.begin(); itr != mGuildMap.end(); ++itr)
{
- Guild* pGuild = *itr;
+ Guild* pGuild = itr->second;
if (pGuild)
{
if (!pGuild->Validate())
diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h
index bcc80bcc77e..ce5fd431686 100755
--- a/src/server/game/Globals/ObjectMgr.h
+++ b/src/server/game/Globals/ObjectMgr.h
@@ -594,7 +594,7 @@ class ObjectMgr
typedef std::set<Group *> GroupSet;
typedef std::vector<Group *> GroupStorage;
- typedef std::vector <Guild *> GuildMap;
+ typedef UNORDERED_MAP<uint32, Guild*> GuildMap;
typedef UNORDERED_MAP<uint32, ArenaTeam*> ArenaTeamMap;