CScriptTemplate: Collapse loop to find_if() in RemoveObject()

This commit is contained in:
Lioncash 2020-06-19 23:43:26 -04:00
parent 731e34b90b
commit 71fd2b8754
2 changed files with 10 additions and 10 deletions

View File

@ -5,6 +5,7 @@
#include "Core/Resource/Animation/CAnimSet.h"
#include <Common/Log.h>
#include <algorithm>
#include <string>
// Old constructor
@ -286,16 +287,15 @@ void CScriptTemplate::AddObject(CScriptObject *pObject)
mObjectList.push_back(pObject);
}
void CScriptTemplate::RemoveObject(CScriptObject *pObject)
void CScriptTemplate::RemoveObject(const CScriptObject *pObject)
{
for (auto it = mObjectList.begin(); it != mObjectList.end(); it++)
{
if (*it == pObject)
{
mObjectList.erase(it);
break;
}
}
const auto iter = std::find_if(mObjectList.cbegin(), mObjectList.cend(),
[pObject](const auto* ptr) { return ptr == pObject; });
if (iter == mObjectList.cend())
return;
mObjectList.erase(iter);
}
void CScriptTemplate::SortObjects()

View File

@ -172,7 +172,7 @@ public:
uint32 NumObjects() const;
const std::list<CScriptObject*>& ObjectList() const;
void AddObject(CScriptObject *pObject);
void RemoveObject(CScriptObject *pObject);
void RemoveObject(const CScriptObject *pObject);
void SortObjects();
private: