Optimize EntityList::RemoveGroup/RemoveRaid

lambdas are cheating btw.
This commit is contained in:
Michael Cook (mackal) 2015-01-09 02:44:20 -05:00
parent 4c9653d204
commit c33973f20a

View File

@ -2251,44 +2251,30 @@ bool EntityList::RemoveCorpse(uint16 delete_id)
bool EntityList::RemoveGroup(uint32 delete_id) bool EntityList::RemoveGroup(uint32 delete_id)
{ {
std::list<Group *>::iterator iterator; auto it = std::find_if(group_list.begin(), group_list.end(),
[delete_id](const Group *a) { return a->GetID() == delete_id; });
iterator = group_list.begin(); if (it == group_list.end()) {
while(iterator != group_list.end())
{
if((*iterator)->GetID() == delete_id) {
group_list.remove(*iterator);
delete *iterator;
#if EQDEBUG >= 5 #if EQDEBUG >= 5
CheckGroupList (__FILE__, __LINE__); CheckGroupList (__FILE__, __LINE__);
#endif #endif
return true; return false;
}
++iterator;
} }
#if EQDEBUG >= 5 auto group = *it;
CheckGroupList (__FILE__, __LINE__); group_list.erase(it);
#endif delete group;
return false; return true;
} }
bool EntityList::RemoveRaid(uint32 delete_id) bool EntityList::RemoveRaid(uint32 delete_id)
{ {
std::list<Raid *>::iterator iterator; auto it = std::find_if(raid_list.begin(), raid_list.end(),
[delete_id](const Raid *a) { return a->GetID() == delete_id; });
iterator = raid_list.begin(); if (it == raid_list.end())
return false;
while(iterator != raid_list.end()) auto raid = *it;
{ raid_list.erase(it);
if((*iterator)->GetID() == delete_id) { delete raid;
raid_list.remove(*iterator); return true;
delete *iterator;
return true;
}
++iterator;
}
return false;
} }
void EntityList::Clear() void EntityList::Clear()