mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 07:23:54 +00:00
Reduce temporary allocations on ESM loading
By moving objects instead of copying when possible.
This commit is contained in:
parent
a1b96cb9cc
commit
f2188d2533
6 changed files with 18 additions and 15 deletions
|
@ -108,11 +108,13 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
|
||||||
|
|
||||||
Record<CellRef> record;
|
Record<CellRef> record;
|
||||||
record.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
|
record.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_ModifiedOnly;
|
||||||
(base ? record.mBase : record.mModified) = ref;
|
const ESM::RefNum refNum = ref.mRefNum;
|
||||||
|
std::string refId = ref.mId;
|
||||||
|
(base ? record.mBase : record.mModified) = std::move(ref);
|
||||||
|
|
||||||
appendRecord (record);
|
appendRecord (record);
|
||||||
|
|
||||||
cache.insert (std::make_pair (ref.mRefNum, ref.mId));
|
cache.emplace(refNum, std::move(refId));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -123,7 +125,7 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
|
||||||
|
|
||||||
Record<CellRef> record = getRecord (index);
|
Record<CellRef> record = getRecord (index);
|
||||||
record.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_Modified;
|
record.mState = base ? RecordBase::State_BaseOnly : RecordBase::State_Modified;
|
||||||
(base ? record.mBase : record.mModified) = ref;
|
(base ? record.mBase : record.mModified) = std::move(ref);
|
||||||
|
|
||||||
setRecord (index, record);
|
setRecord (index, record);
|
||||||
}
|
}
|
||||||
|
|
|
@ -241,7 +241,7 @@ namespace MWRender
|
||||||
if (model.empty()) continue;
|
if (model.empty()) continue;
|
||||||
model = "meshes/" + model;
|
model = "meshes/" + model;
|
||||||
|
|
||||||
instances[model].emplace_back(ref, model);
|
instances[model].emplace_back(std::move(ref), std::move(model));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -432,7 +432,7 @@ namespace MWRender
|
||||||
if (!typeFilter(type,size>=2)) continue;
|
if (!typeFilter(type,size>=2)) continue;
|
||||||
if (deleted) { refs.erase(ref.mRefNum); continue; }
|
if (deleted) { refs.erase(ref.mRefNum); continue; }
|
||||||
if (ref.mRefNum.fromGroundcoverFile()) continue;
|
if (ref.mRefNum.fromGroundcoverFile()) continue;
|
||||||
refs[ref.mRefNum] = ref;
|
refs[ref.mRefNum] = std::move(ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (std::exception&)
|
catch (std::exception&)
|
||||||
|
@ -448,7 +448,7 @@ namespace MWRender
|
||||||
if (deleted) { refs.erase(ref.mRefNum); continue; }
|
if (deleted) { refs.erase(ref.mRefNum); continue; }
|
||||||
int type = store.findStatic(ref.mRefID);
|
int type = store.findStatic(ref.mRefID);
|
||||||
if (!typeFilter(type,size>=2)) continue;
|
if (!typeFilter(type,size>=2)) continue;
|
||||||
refs[ref.mRefNum] = ref;
|
refs[ref.mRefNum] = std::move(ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -566,7 +566,8 @@ namespace MWWorld
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
mIds.push_back (Misc::StringUtils::lowerCase (ref.mRefID));
|
Misc::StringUtils::lowerCaseInPlace(ref.mRefID);
|
||||||
|
mIds.push_back(std::move(ref.mRefID));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace
|
||||||
else if (std::find(cell.mMovedRefs.begin(), cell.mMovedRefs.end(), ref.mRefNum) == cell.mMovedRefs.end())
|
else if (std::find(cell.mMovedRefs.begin(), cell.mMovedRefs.end(), ref.mRefNum) == cell.mMovedRefs.end())
|
||||||
{
|
{
|
||||||
Misc::StringUtils::lowerCaseInPlace(ref.mRefID);
|
Misc::StringUtils::lowerCaseInPlace(ref.mRefID);
|
||||||
refs[ref.mRefNum] = ref.mRefID;
|
refs[ref.mRefNum] = std::move(ref.mRefID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,9 +42,9 @@ namespace
|
||||||
refs.erase(it.first.mRefNum);
|
refs.erase(it.first.mRefNum);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ESM::CellRef ref = it.first;
|
std::string refId = it.first.mRefID;
|
||||||
Misc::StringUtils::lowerCaseInPlace(ref.mRefID);
|
Misc::StringUtils::lowerCaseInPlace(refId);
|
||||||
refs[ref.mRefNum] = ref.mRefID;
|
refs[it.first.mRefNum] = std::move(refId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -254,8 +254,8 @@ void ESMStore::countRecords()
|
||||||
readRefs(*it, refs, readers);
|
readRefs(*it, refs, readers);
|
||||||
for(auto it = mCells.extBegin(); it != mCells.extEnd(); it++)
|
for(auto it = mCells.extBegin(); it != mCells.extEnd(); it++)
|
||||||
readRefs(*it, refs, readers);
|
readRefs(*it, refs, readers);
|
||||||
for(const auto& pair : refs)
|
for(auto& pair : refs)
|
||||||
mRefCount[pair.second]++;
|
mRefCount[std::move(pair.second)]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ESMStore::getRefCount(const std::string& id) const
|
int ESMStore::getRefCount(const std::string& id) const
|
||||||
|
|
|
@ -518,9 +518,9 @@ namespace MWWorld
|
||||||
// But there may be duplicates here!
|
// But there may be duplicates here!
|
||||||
ESM::CellRefTracker::iterator iter = std::find_if(cellAlt->mLeasedRefs.begin(), cellAlt->mLeasedRefs.end(), ESM::CellRefTrackerPredicate(ref.mRefNum));
|
ESM::CellRefTracker::iterator iter = std::find_if(cellAlt->mLeasedRefs.begin(), cellAlt->mLeasedRefs.end(), ESM::CellRefTrackerPredicate(ref.mRefNum));
|
||||||
if (iter == cellAlt->mLeasedRefs.end())
|
if (iter == cellAlt->mLeasedRefs.end())
|
||||||
cellAlt->mLeasedRefs.push_back(std::make_pair(ref, deleted));
|
cellAlt->mLeasedRefs.emplace_back(std::move(ref), deleted);
|
||||||
else
|
else
|
||||||
*iter = std::make_pair(ref, deleted);
|
*iter = std::make_pair(std::move(ref), deleted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const ESM::Cell *Store<ESM::Cell>::search(const std::string &id) const
|
const ESM::Cell *Store<ESM::Cell>::search(const std::string &id) const
|
||||||
|
|
Loading…
Reference in a new issue