From c8ebbc860bdb19c7808b8315a8478c39ec66f00b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 16 Jun 2020 18:45:47 -0400 Subject: [PATCH] CMaterialSet: Collapse loop into find_if Same behavior, explicit intent. --- src/Core/Resource/CMaterialSet.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Core/Resource/CMaterialSet.h b/src/Core/Resource/CMaterialSet.h index 4b68676e..a9f1fda9 100644 --- a/src/Core/Resource/CMaterialSet.h +++ b/src/Core/Resource/CMaterialSet.h @@ -5,6 +5,7 @@ #include "CTexture.h" #include #include +#include class CMaterialSet { @@ -47,13 +48,13 @@ public: CMaterial* MaterialByName(const TString& rkName) { - for (auto it = mMaterials.begin(); it != mMaterials.end(); it++) - { - if ((*it)->Name() == rkName) - return it->get(); - } + const auto iter = std::find_if(mMaterials.begin(), mMaterials.end(), + [&rkName](const auto& entry) { return entry->Name() == rkName; }); - return nullptr; + if (iter == mMaterials.cend()) + return nullptr; + + return iter->get(); } uint32 MaterialIndexByName(const TString& rkName)