diff --git a/apps/opencs/model/doc/savingstages.cpp b/apps/opencs/model/doc/savingstages.cpp index bf1db8030c..39c0420333 100644 --- a/apps/opencs/model/doc/savingstages.cpp +++ b/apps/opencs/model/doc/savingstages.cpp @@ -236,7 +236,7 @@ CSMDoc::CollectionReferencesStage::CollectionReferencesStage(Document& document, int CSMDoc::CollectionReferencesStage::setup() { - mState.getSubRecords().clear(); + mState.clearSubRecords(); int size = mDocument.getData().getReferences().getSize(); @@ -260,7 +260,7 @@ void CSMDoc::CollectionReferencesStage::perform(int stage, Messages& messages) const ESM::RefId& cellId = record.get().mOriginalCell.empty() ? record.get().mCell : record.get().mOriginalCell; - std::deque& indices = mState.getSubRecords()[cellId.getRefIdString()]; + std::deque& indices = mState.getOrInsertSubRecord(cellId); // collect moved references at the end of the container const bool interior = !cellId.startsWith("#"); @@ -360,11 +360,9 @@ void CSMDoc::WriteCellCollectionStage::perform(int stage, Messages& messages) std::deque tempRefs; std::deque persistentRefs; - std::map>::const_iterator references - = mState.getSubRecords().find(cell.get().mId.getRefIdString()); + const std::deque* references = mState.findSubRecord(cell.get().mId); - if (cell.isModified() || cell.mState == CSMWorld::RecordBase::State_Deleted - || references != mState.getSubRecords().end()) + if (cell.isModified() || cell.mState == CSMWorld::RecordBase::State_Deleted || references != nullptr) { CSMWorld::Cell cellRecord = cell.get(); const bool interior = !cellRecord.mId.startsWith("#"); @@ -372,10 +370,9 @@ void CSMDoc::WriteCellCollectionStage::perform(int stage, Messages& messages) // count new references and adjust RefNumCount accordingsly unsigned int newRefNum = cellRecord.mRefNumCounter; - if (references != mState.getSubRecords().end()) + if (references != nullptr) { - for (std::deque::const_iterator iter(references->second.begin()); iter != references->second.end(); - ++iter) + for (std::deque::const_iterator iter(references->begin()); iter != references->end(); ++iter) { const CSMWorld::Record& ref = mDocument.getData().getReferences().getRecord(*iter); @@ -421,10 +418,10 @@ void CSMDoc::WriteCellCollectionStage::perform(int stage, Messages& messages) cellRecord.save(writer, cell.mState == CSMWorld::RecordBase::State_Deleted); // write references - if (references != mState.getSubRecords().end()) + if (references != nullptr) { writeReferences(persistentRefs, interior, newRefNum); - cellRecord.saveTempMarker(writer, int(references->second.size()) - persistentRefs.size()); + cellRecord.saveTempMarker(writer, static_cast(references->size()) - persistentRefs.size()); writeReferences(tempRefs, interior, newRefNum); } diff --git a/apps/opencs/model/doc/savingstate.cpp b/apps/opencs/model/doc/savingstate.cpp index 169f572154..aec2d0fd9b 100644 --- a/apps/opencs/model/doc/savingstate.cpp +++ b/apps/opencs/model/doc/savingstate.cpp @@ -68,7 +68,20 @@ bool CSMDoc::SavingState::isProjectFile() const return mProjectFile; } -std::map, Misc::StringUtils::CiComp>& CSMDoc::SavingState::getSubRecords() +const std::deque* CSMDoc::SavingState::findSubRecord(const ESM::RefId& refId) const { - return mSubRecords; + const auto it = mSubRecords.find(refId); + if (it == mSubRecords.end()) + return nullptr; + return &it->second; +} + +std::deque& CSMDoc::SavingState::getOrInsertSubRecord(const ESM::RefId& refId) +{ + return mSubRecords[refId]; +} + +void CSMDoc::SavingState::clearSubRecords() +{ + mSubRecords.clear(); } diff --git a/apps/opencs/model/doc/savingstate.hpp b/apps/opencs/model/doc/savingstate.hpp index daa65ef815..c42dff0366 100644 --- a/apps/opencs/model/doc/savingstate.hpp +++ b/apps/opencs/model/doc/savingstate.hpp @@ -8,9 +8,9 @@ #include #include - #include #include + namespace CSMDoc { class Operation; @@ -26,7 +26,7 @@ namespace CSMDoc ESM::ESMWriter mWriter; std::filesystem::path mProjectPath; bool mProjectFile; - std::map, Misc::StringUtils::CiComp> mSubRecords; // record ID, list of subrecords + std::map> mSubRecords; // record ID, list of subrecords public: SavingState(Operation& operation, std::filesystem::path projectPath, ToUTF8::FromType encoding); @@ -47,7 +47,11 @@ namespace CSMDoc bool isProjectFile() const; ///< Currently saving project file? (instead of content file) - std::map, Misc::StringUtils::CiComp>& getSubRecords(); + const std::deque* findSubRecord(const ESM::RefId& refId) const; + + std::deque& getOrInsertSubRecord(const ESM::RefId& refId); + + void clearSubRecords(); }; }