From c33973f20aa31a66650c55e296762c7dc08eff0b Mon Sep 17 00:00:00 2001 From: "Michael Cook (mackal)" Date: Fri, 9 Jan 2015 02:44:20 -0500 Subject: [PATCH] Optimize EntityList::RemoveGroup/RemoveRaid lambdas are cheating btw. --- zone/entity.cpp | 48 +++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/zone/entity.cpp b/zone/entity.cpp index 9905374fd..296144a3d 100644 --- a/zone/entity.cpp +++ b/zone/entity.cpp @@ -2251,44 +2251,30 @@ bool EntityList::RemoveCorpse(uint16 delete_id) bool EntityList::RemoveGroup(uint32 delete_id) { - std::list::iterator iterator; - - iterator = group_list.begin(); - - while(iterator != group_list.end()) - { - if((*iterator)->GetID() == delete_id) { - group_list.remove(*iterator); - delete *iterator; + auto it = std::find_if(group_list.begin(), group_list.end(), + [delete_id](const Group *a) { return a->GetID() == delete_id; }); + if (it == group_list.end()) { #if EQDEBUG >= 5 - CheckGroupList (__FILE__, __LINE__); + CheckGroupList (__FILE__, __LINE__); #endif - return true; - } - ++iterator; + return false; } -#if EQDEBUG >= 5 - CheckGroupList (__FILE__, __LINE__); -#endif - return false; + auto group = *it; + group_list.erase(it); + delete group; + return true; } bool EntityList::RemoveRaid(uint32 delete_id) { - std::list::iterator iterator; - - iterator = raid_list.begin(); - - while(iterator != raid_list.end()) - { - if((*iterator)->GetID() == delete_id) { - raid_list.remove(*iterator); - delete *iterator; - return true; - } - ++iterator; - } - return false; + auto it = std::find_if(raid_list.begin(), raid_list.end(), + [delete_id](const Raid *a) { return a->GetID() == delete_id; }); + if (it == raid_list.end()) + return false; + auto raid = *it; + raid_list.erase(it); + delete raid; + return true; } void EntityList::Clear()