From 4eac1371090671981fbff6896e5b64e21e1706ac Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Tue, 11 Jul 2023 22:10:39 +0200 Subject: [PATCH] Change control flow to be easier to understand --- components/esm3/infoorder.hpp | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/components/esm3/infoorder.hpp b/components/esm3/infoorder.hpp index 154cf8970f..5ca98cabd5 100644 --- a/components/esm3/infoorder.hpp +++ b/components/esm3/infoorder.hpp @@ -38,27 +38,19 @@ namespace ESM Item& item = it->second; - const auto insertOrSplice = [&](typename std::list::const_iterator before) { - if (item.mPosition == mOrderedInfo.end()) - item.mPosition = mOrderedInfo.insert(before, std::forward(value)); - else - mOrderedInfo.splice(before, mOrderedInfo, item.mPosition); - }; - - if (value.mPrev.empty()) - { - insertOrSplice(mOrderedInfo.begin()); - return; - } - - const auto prevIt = mInfoPositions.find(value.mPrev); - if (prevIt != mInfoPositions.end()) + auto before = mOrderedInfo.begin(); + if (!value.mPrev.empty()) { - insertOrSplice(std::next(prevIt->second.mPosition)); - return; + const auto prevIt = mInfoPositions.find(value.mPrev); + if (prevIt != mInfoPositions.end()) + before = std::next(prevIt->second.mPosition); + else + before = mOrderedInfo.end(); } - - insertOrSplice(mOrderedInfo.end()); + if (item.mPosition == mOrderedInfo.end()) + item.mPosition = mOrderedInfo.insert(before, std::forward(value)); + else + mOrderedInfo.splice(before, mOrderedInfo, item.mPosition); } void removeInfo(const RefId& infoRefId)