1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-30 08:15:37 +00:00

Change control flow to be easier to understand

This commit is contained in:
Evil Eye 2023-07-11 22:10:39 +02:00
parent 09147934fb
commit 4eac137109

View file

@ -38,27 +38,19 @@ namespace ESM
Item& item = it->second;
const auto insertOrSplice = [&](typename std::list<T>::const_iterator before) {
if (item.mPosition == mOrderedInfo.end())
item.mPosition = mOrderedInfo.insert(before, std::forward<V>(value));
auto before = mOrderedInfo.begin();
if (!value.mPrev.empty())
{
const auto prevIt = mInfoPositions.find(value.mPrev);
if (prevIt != mInfoPositions.end())
before = std::next(prevIt->second.mPosition);
else
mOrderedInfo.splice(before, mOrderedInfo, item.mPosition);
};
if (value.mPrev.empty())
{
insertOrSplice(mOrderedInfo.begin());
return;
before = mOrderedInfo.end();
}
const auto prevIt = mInfoPositions.find(value.mPrev);
if (prevIt != mInfoPositions.end())
{
insertOrSplice(std::next(prevIt->second.mPosition));
return;
}
insertOrSplice(mOrderedInfo.end());
if (item.mPosition == mOrderedInfo.end())
item.mPosition = mOrderedInfo.insert(before, std::forward<V>(value));
else
mOrderedInfo.splice(before, mOrderedInfo, item.mPosition);
}
void removeInfo(const RefId& infoRefId)