From fb344d27e033da9b095d677f2cf5ae4b6f44d05a Mon Sep 17 00:00:00 2001 From: fredzio Date: Fri, 14 May 2021 23:38:39 +0200 Subject: [PATCH] Use insert_or_assign() instead of hand rolled version. --- apps/openmw/mwworld/store.cpp | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/apps/openmw/mwworld/store.cpp b/apps/openmw/mwworld/store.cpp index fb66b0a1d..53ba3cfc2 100644 --- a/apps/openmw/mwworld/store.cpp +++ b/apps/openmw/mwworld/store.cpp @@ -58,10 +58,7 @@ namespace MWWorld record.load(esm, isDeleted); - // Try to overwrite existing record - std::pair ret = mStatic.insert(std::make_pair(record.mIndex, record)); - if (!ret.second) - ret.first->second = record; + mStatic.insert_or_assign(record.mIndex, record); } template int IndexedStore::getSize() const @@ -181,11 +178,9 @@ namespace MWWorld record.load(esm, isDeleted); Misc::StringUtils::lowerCaseInPlace(record.mId); - std::pair inserted = mStatic.insert(std::make_pair(record.mId, record)); + std::pair inserted = mStatic.insert_or_assign(record.mId, record); if (inserted.second) mShared.push_back(&inserted.first->second); - else - inserted.first->second = record; return RecordId(record.mId, isDeleted); } @@ -235,28 +230,20 @@ namespace MWWorld if(it == mStatic.end()) return nullptr; } - std::pair result = - mDynamic.insert(std::pair(id, item)); + std::pair result = mDynamic.insert_or_assign(id, item); T *ptr = &result.first->second; - if (result.second) { + if (result.second) mShared.push_back(ptr); - } else { - *ptr = item; - } return ptr; } template T *Store::insertStatic(const T &item) { std::string id = Misc::StringUtils::lowerCase(item.mId); - std::pair result = - mStatic.insert(std::pair(id, item)); + std::pair result = mStatic.insert_or_assign(id, item); T *ptr = &result.first->second; - if (result.second) { + if (result.second) mShared.push_back(ptr); - } else { - *ptr = item; - } return ptr; } template