From 71fd2b87541a9168330b9a1d942b0b0c147eee1e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 19 Jun 2020 23:43:26 -0400 Subject: [PATCH] CScriptTemplate: Collapse loop to find_if() in RemoveObject() --- src/Core/Resource/Script/CScriptTemplate.cpp | 18 +++++++++--------- src/Core/Resource/Script/CScriptTemplate.h | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Core/Resource/Script/CScriptTemplate.cpp b/src/Core/Resource/Script/CScriptTemplate.cpp index 64e6a15a..77819e45 100644 --- a/src/Core/Resource/Script/CScriptTemplate.cpp +++ b/src/Core/Resource/Script/CScriptTemplate.cpp @@ -5,6 +5,7 @@ #include "Core/Resource/Animation/CAnimSet.h" #include +#include #include // 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() diff --git a/src/Core/Resource/Script/CScriptTemplate.h b/src/Core/Resource/Script/CScriptTemplate.h index e9649806..4056f994 100644 --- a/src/Core/Resource/Script/CScriptTemplate.h +++ b/src/Core/Resource/Script/CScriptTemplate.h @@ -172,7 +172,7 @@ public: uint32 NumObjects() const; const std::list& ObjectList() const; void AddObject(CScriptObject *pObject); - void RemoveObject(CScriptObject *pObject); + void RemoveObject(const CScriptObject *pObject); void SortObjects(); private: