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.
pull/3212/head
Bo Svensson 3 years ago committed by GitHub
parent d3b2503111
commit 213faa6695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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)
{
// TODO: we have many similar copies of this code.
for (size_t i = 0; i < cell.mContextList.size(); i++)
{
size_t index = cell.mContextList[i].index;
@ -301,12 +302,14 @@ void ESMStore::setUp(bool validateRecords)
if (validateRecords)
{
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())
return;
std::vector<Ref> refs;
@ -324,6 +327,8 @@ void ESMStore::countRecords()
if (value.mRefID != deletedRefID)
{
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)];
}
};
@ -332,7 +337,8 @@ void ESMStore::countRecords()
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())
return 0;
return it->second;

@ -79,7 +79,7 @@ namespace MWWorld
IDMap mIds;
IDMap mStaticIds;
IDMap mRefCount;
std::unordered_map<std::string, int> mRefCount;
std::map<int, StoreBase *> mStores;
@ -90,7 +90,7 @@ namespace MWWorld
/// Validate entries in store after setup
void validate();
void countRecords();
void countAllCellRefs();
template<class T>
void removeMissingObjects(Store<T>& store);

Loading…
Cancel
Save