diff --git a/src/backend/metadata.cpp b/src/backend/metadata.cpp index a439934e..5dbe4876 100644 --- a/src/backend/metadata.cpp +++ b/src/backend/metadata.cpp @@ -271,6 +271,12 @@ namespace boss { for (vector::const_iterator it = records.begin(),endIt = records.end(); it != endIt; ++it) formIDs.insert(FormID(plugins, *it)); + //Calculate how many records are override records. + for (set::const_iterator it = formIDs.begin(), endIt=formIDs.end(); it != endIt; ++it) { + if (!boost::iequals(it->Plugin(), name)) + ++numOverrideRecords; + } + //If the name passed ends in '.ghost', that should be trimmed. if (boost::iends_with(name, ".ghost")) name = name.substr(0, name.length() - 6); @@ -514,19 +520,17 @@ namespace boss { return !(*this == rhs); } - std::set Plugin::FormIDs() const { + const std::set& Plugin::FormIDs() const { return formIDs; } bool Plugin::DoFormIDsOverlap(const Plugin& plugin) const { //Basically std::set_intersection except with an early exit instead of an append to results. - set otherFormIDs = plugin.FormIDs(); - set::const_iterator i = formIDs.begin(), - j = otherFormIDs.begin(), + j = plugin.FormIDs().begin(), iend = formIDs.end(), - jend = otherFormIDs.end(); + jend = plugin.FormIDs().end(); while (i != iend && j != jend) { if (*i < *j) @@ -541,12 +545,7 @@ namespace boss { } size_t Plugin::NumOverrideFormIDs() const { - size_t num = 0; - for (set::const_iterator it = formIDs.begin(), endIt=formIDs.end(); it != endIt; ++it) { - if (!boost::iequals(it->Plugin(), name)) - ++num; - } - return num; + return numOverrideRecords; } std::set Plugin::OverlapFormIDs(const Plugin& plugin) const { @@ -731,7 +730,7 @@ namespace boss { } //The map maps each plugin name to a vector of names of plugins that overlap with it and should load before it. - void CalcPluginOverlaps(const std::list& plugins, std::map< std::string, std::vector >& overlapMap) { + void CalcPluginOverlaps(const std::list& plugins, boost::unordered_map< std::string, std::vector >& overlapMap) { for (list::const_iterator it=plugins.begin(), endit=plugins.end(); it != endit; @@ -739,6 +738,7 @@ namespace boss { list::const_iterator jt = it; ++jt; for (jt, endit; jt != endit; ++jt) { + BOOST_LOG_TRIVIAL(trace) << "Checking for FormID overlap between \"" << it->Name() << "\" and \"" << jt->Name() << "\"."; if (it->DoFormIDsOverlap(*jt)) { std::string key; std::string value; @@ -749,7 +749,7 @@ namespace boss { key = it->Name(); value = jt->Name(); } - map< string, vector >::iterator mapIt = overlapMap.find(key); + boost::unordered_map< string, vector >::iterator mapIt = overlapMap.find(key); if (mapIt == overlapMap.end()) { overlapMap.insert(pair >(key, vector(1, value))); } else { diff --git a/src/backend/metadata.h b/src/backend/metadata.h index ddbc4617..a36d9894 100644 --- a/src/backend/metadata.h +++ b/src/backend/metadata.h @@ -32,6 +32,8 @@ #include #include +#include + namespace boss { @@ -150,7 +152,7 @@ namespace boss { std::list Messages() const; std::set Tags() const; - std::set FormIDs() const; + const std::set& FormIDs() const; std::vector Masters() const; bool IsMaster() const; //Checks master bit flag. std::string Version() const; @@ -198,6 +200,9 @@ namespace boss { std::string version; //Obtained from description field. bool isMaster; uint32_t crc; + + //Useful caches. + size_t numOverrideRecords; }; bool operator == (const File& lhs, const Plugin& rhs); @@ -213,7 +218,7 @@ namespace boss { bool IsPlugin(const std::string& file); //The map maps each plugin name to a vector of names of plugins that overlap with it and should load before it. - void CalcPluginOverlaps(const std::list& plugins, std::map< std::string, std::vector >& overlapMap); + void CalcPluginOverlaps(const std::list& plugins, boost::unordered_map< std::string, std::vector >& overlapMap); } #endif