From 6436184a3f47af7c674b53f6d9990c2ef3236230 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 14 Apr 2020 16:40:11 -0400 Subject: [PATCH] CWorld: Make use of find_if in GetAreaIdForSaveId() Same behavior minus any explicit mutable state. --- Runtime/World/CWorld.cpp | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/Runtime/World/CWorld.cpp b/Runtime/World/CWorld.cpp index 03ca4b8ef..79a6bb5b2 100644 --- a/Runtime/World/CWorld.cpp +++ b/Runtime/World/CWorld.cpp @@ -712,19 +712,20 @@ bool CWorld::AreSkyNeedsMet() const { } TAreaId CWorld::GetAreaIdForSaveId(s32 saveId) const { - if (saveId == -1) + if (saveId == -1) { return kInvalidAreaId; - - if (x18_areas.size() <= 0) - return kInvalidAreaId; - - TAreaId cur = 0; - for (const auto& area : x18_areas) { - if (area->x88_areaId == saveId) - return cur; - ++cur; } - return kInvalidAreaId; + if (x18_areas.empty()) { + return kInvalidAreaId; + } + + const auto iter = std::find_if(x18_areas.cbegin(), x18_areas.cend(), + [saveId](const auto& area) { return area->x88_areaId == saveId; }); + if (iter == x18_areas.cend()) { + return kInvalidAreaId; + } + + return TAreaId(std::distance(x18_areas.cbegin(), iter)); } } // namespace urde