CScriptTemplate: Collapse loop to find_if() in RemoveObject()
This commit is contained in:
parent
731e34b90b
commit
71fd2b8754
|
@ -5,6 +5,7 @@
|
||||||
#include "Core/Resource/Animation/CAnimSet.h"
|
#include "Core/Resource/Animation/CAnimSet.h"
|
||||||
#include <Common/Log.h>
|
#include <Common/Log.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
// Old constructor
|
// Old constructor
|
||||||
|
@ -286,16 +287,15 @@ void CScriptTemplate::AddObject(CScriptObject *pObject)
|
||||||
mObjectList.push_back(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++)
|
const auto iter = std::find_if(mObjectList.cbegin(), mObjectList.cend(),
|
||||||
{
|
[pObject](const auto* ptr) { return ptr == pObject; });
|
||||||
if (*it == pObject)
|
|
||||||
{
|
if (iter == mObjectList.cend())
|
||||||
mObjectList.erase(it);
|
return;
|
||||||
break;
|
|
||||||
}
|
mObjectList.erase(iter);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CScriptTemplate::SortObjects()
|
void CScriptTemplate::SortObjects()
|
||||||
|
|
|
@ -172,7 +172,7 @@ public:
|
||||||
uint32 NumObjects() const;
|
uint32 NumObjects() const;
|
||||||
const std::list<CScriptObject*>& ObjectList() const;
|
const std::list<CScriptObject*>& ObjectList() const;
|
||||||
void AddObject(CScriptObject *pObject);
|
void AddObject(CScriptObject *pObject);
|
||||||
void RemoveObject(CScriptObject *pObject);
|
void RemoveObject(const CScriptObject *pObject);
|
||||||
void SortObjects();
|
void SortObjects();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue