mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-27 04:10:24 +00:00
restores countRecords optimisations (#3210)
With this PR we restore @elsid 's optimisations of countRecords we have unintentionally discarded in PR #3197. In addition, we give it a more appropriate name and add comments concerning its peculiar background.
This commit is contained in:
parent
d3b2503111
commit
213faa6695
2 changed files with 11 additions and 5 deletions
|
@ -29,6 +29,7 @@ namespace
|
||||||
|
|
||||||
void readRefs(const ESM::Cell& cell, std::vector<Ref>& refs, std::vector<std::string>& refIDs, std::vector<ESM::ESMReader>& readers)
|
void readRefs(const ESM::Cell& cell, std::vector<Ref>& refs, std::vector<std::string>& refIDs, std::vector<ESM::ESMReader>& readers)
|
||||||
{
|
{
|
||||||
|
// TODO: we have many similar copies of this code.
|
||||||
for (size_t i = 0; i < cell.mContextList.size(); i++)
|
for (size_t i = 0; i < cell.mContextList.size(); i++)
|
||||||
{
|
{
|
||||||
size_t index = cell.mContextList[i].index;
|
size_t index = cell.mContextList[i].index;
|
||||||
|
@ -301,12 +302,14 @@ void ESMStore::setUp(bool validateRecords)
|
||||||
if (validateRecords)
|
if (validateRecords)
|
||||||
{
|
{
|
||||||
validate();
|
validate();
|
||||||
countRecords();
|
countAllCellRefs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESMStore::countRecords()
|
void ESMStore::countAllCellRefs()
|
||||||
{
|
{
|
||||||
|
// TODO: We currently need to read entire files here again.
|
||||||
|
// We should consider consolidating or deferring this reading.
|
||||||
if(!mRefCount.empty())
|
if(!mRefCount.empty())
|
||||||
return;
|
return;
|
||||||
std::vector<Ref> refs;
|
std::vector<Ref> refs;
|
||||||
|
@ -324,6 +327,8 @@ void ESMStore::countRecords()
|
||||||
if (value.mRefID != deletedRefID)
|
if (value.mRefID != deletedRefID)
|
||||||
{
|
{
|
||||||
std::string& refId = refIDs[value.mRefID];
|
std::string& refId = refIDs[value.mRefID];
|
||||||
|
// We manually lower case IDs here for the time being to improve performance.
|
||||||
|
Misc::StringUtils::lowerCaseInPlace(refId);
|
||||||
++mRefCount[std::move(refId)];
|
++mRefCount[std::move(refId)];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -332,7 +337,8 @@ void ESMStore::countRecords()
|
||||||
|
|
||||||
int ESMStore::getRefCount(const std::string& id) const
|
int ESMStore::getRefCount(const std::string& id) const
|
||||||
{
|
{
|
||||||
auto it = mRefCount.find(id);
|
const std::string lowerId = Misc::StringUtils::lowerCase(id);
|
||||||
|
auto it = mRefCount.find(lowerId);
|
||||||
if(it == mRefCount.end())
|
if(it == mRefCount.end())
|
||||||
return 0;
|
return 0;
|
||||||
return it->second;
|
return it->second;
|
||||||
|
|
|
@ -79,7 +79,7 @@ namespace MWWorld
|
||||||
IDMap mIds;
|
IDMap mIds;
|
||||||
IDMap mStaticIds;
|
IDMap mStaticIds;
|
||||||
|
|
||||||
IDMap mRefCount;
|
std::unordered_map<std::string, int> mRefCount;
|
||||||
|
|
||||||
std::map<int, StoreBase *> mStores;
|
std::map<int, StoreBase *> mStores;
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ namespace MWWorld
|
||||||
/// Validate entries in store after setup
|
/// Validate entries in store after setup
|
||||||
void validate();
|
void validate();
|
||||||
|
|
||||||
void countRecords();
|
void countAllCellRefs();
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void removeMissingObjects(Store<T>& store);
|
void removeMissingObjects(Store<T>& store);
|
||||||
|
|
Loading…
Reference in a new issue