1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-07-05 16:11:35 +00:00

Use ranged for loop

This commit is contained in:
elsid 2023-05-26 19:26:23 +02:00
parent a04eb9d26c
commit b6cd6402cc
No known key found for this signature in database
GPG key ID: 4DE04C198CBA7625
2 changed files with 12 additions and 14 deletions

View file

@ -334,14 +334,14 @@ MWWorld::CellStore& MWWorld::WorldModel::getCellByPosition(
MWWorld::Ptr MWWorld::WorldModel::getPtr(const ESM::RefId& name) MWWorld::Ptr MWWorld::WorldModel::getPtr(const ESM::RefId& name)
{ {
// First check the cache for (const auto& [cachedId, cellStore] : mIdCache)
for (IdCache::iterator iter(mIdCache.begin()); iter != mIdCache.end(); ++iter) {
if (iter->first == name && iter->second) if (cachedId != name || cellStore == nullptr)
{ continue;
Ptr ptr = iter->second->getPtr(name); Ptr ptr = cellStore->getPtr(name);
if (!ptr.isEmpty()) if (!ptr.isEmpty())
return ptr; return ptr;
} }
// Then check cells that are already listed // Then check cells that are already listed
// Search in reverse, this is a workaround for an ambiguous chargen_plank reference in the vanilla game. // Search in reverse, this is a workaround for an ambiguous chargen_plank reference in the vanilla game.
@ -423,10 +423,10 @@ int MWWorld::WorldModel::countSavedGameRecords() const
void MWWorld::WorldModel::write(ESM::ESMWriter& writer, Loading::Listener& progress) const void MWWorld::WorldModel::write(ESM::ESMWriter& writer, Loading::Listener& progress) const
{ {
for (auto iter(mCells.begin()); iter != mCells.end(); ++iter) for (auto& [id, cellStore] : mCells)
if (iter->second.hasState()) if (cellStore.hasState())
{ {
writeCell(writer, iter->second); writeCell(writer, cellStore);
progress.increaseProgress(); progress.increaseProgress();
} }
} }

View file

@ -89,14 +89,12 @@ namespace MWWorld
bool readRecord(ESM::ESMReader& reader, uint32_t type, const std::map<int, int>& contentFileMap); bool readRecord(ESM::ESMReader& reader, uint32_t type, const std::map<int, int>& contentFileMap);
private: private:
using IdCache = std::vector<std::pair<ESM::RefId, CellStore*>>;
const MWWorld::ESMStore& mStore; const MWWorld::ESMStore& mStore;
ESM::ReadersCache& mReaders; ESM::ReadersCache& mReaders;
mutable std::unordered_map<ESM::RefId, CellStore> mCells; mutable std::unordered_map<ESM::RefId, CellStore> mCells;
mutable std::map<std::string, CellStore*, Misc::StringUtils::CiComp> mInteriors; mutable std::map<std::string, CellStore*, Misc::StringUtils::CiComp> mInteriors;
mutable std::map<ESM::ExteriorCellLocation, CellStore*> mExteriors; mutable std::map<ESM::ExteriorCellLocation, CellStore*> mExteriors;
IdCache mIdCache; std::vector<std::pair<ESM::RefId, CellStore*>> mIdCache;
std::size_t mIdCacheIndex = 0; std::size_t mIdCacheIndex = 0;
std::unordered_map<ESM::RefNum, Ptr> mPtrIndex; std::unordered_map<ESM::RefNum, Ptr> mPtrIndex;
std::size_t mPtrIndexUpdateCounter = 0; std::size_t mPtrIndexUpdateCounter = 0;