Reduce temporary allocations on ESM loading

By moving objects instead of copying when possible.
pull/3091/head
elsid 4 years ago
parent a1b96cb9cc
commit f2188d2533
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40

@ -108,11 +108,13 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
Record<CellRef> record;
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);
cache.insert (std::make_pair (ref.mRefNum, ref.mId));
cache.emplace(refNum, std::move(refId));
}
else
{
@ -123,7 +125,7 @@ void CSMWorld::RefCollection::load (ESM::ESMReader& reader, int cellIndex, bool
Record<CellRef> record = getRecord (index);
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);
}

@ -241,7 +241,7 @@ namespace MWRender
if (model.empty()) continue;
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 (deleted) { refs.erase(ref.mRefNum); continue; }
if (ref.mRefNum.fromGroundcoverFile()) continue;
refs[ref.mRefNum] = ref;
refs[ref.mRefNum] = std::move(ref);
}
}
catch (std::exception&)
@ -448,7 +448,7 @@ namespace MWRender
if (deleted) { refs.erase(ref.mRefNum); continue; }
int type = store.findStatic(ref.mRefID);
if (!typeFilter(type,size>=2)) continue;
refs[ref.mRefNum] = ref;
refs[ref.mRefNum] = std::move(ref);
}
}
}

@ -566,7 +566,8 @@ namespace MWWorld
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)

@ -31,7 +31,7 @@ namespace
else if (std::find(cell.mMovedRefs.begin(), cell.mMovedRefs.end(), ref.mRefNum) == cell.mMovedRefs.end())
{
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);
else
{
ESM::CellRef ref = it.first;
Misc::StringUtils::lowerCaseInPlace(ref.mRefID);
refs[ref.mRefNum] = ref.mRefID;
std::string refId = it.first.mRefID;
Misc::StringUtils::lowerCaseInPlace(refId);
refs[it.first.mRefNum] = std::move(refId);
}
}
}
@ -254,8 +254,8 @@ void ESMStore::countRecords()
readRefs(*it, refs, readers);
for(auto it = mCells.extBegin(); it != mCells.extEnd(); it++)
readRefs(*it, refs, readers);
for(const auto& pair : refs)
mRefCount[pair.second]++;
for(auto& pair : refs)
mRefCount[std::move(pair.second)]++;
}
int ESMStore::getRefCount(const std::string& id) const

@ -518,9 +518,9 @@ namespace MWWorld
// But there may be duplicates here!
ESM::CellRefTracker::iterator iter = std::find_if(cellAlt->mLeasedRefs.begin(), cellAlt->mLeasedRefs.end(), ESM::CellRefTrackerPredicate(ref.mRefNum));
if (iter == cellAlt->mLeasedRefs.end())
cellAlt->mLeasedRefs.push_back(std::make_pair(ref, deleted));
cellAlt->mLeasedRefs.emplace_back(std::move(ref), deleted);
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

Loading…
Cancel
Save