summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Bessent <lost.dragonist@gmail.com>2021-01-16 20:09:12 -0700
committerChris Bessent <lost.dragonist@gmail.com>2021-01-16 20:09:12 -0700
commite69cb90dbef5c5c82f9ae860ccbdeb7f034f885e (patch)
tree7322f85714ad891b17fbc40843025ee97ffa1cc1
parent3dbee687260a02fa523071ec3f351652cb386144 (diff)
Improve performance by changing the map to be case insensitive
-rw-r--r--src/modinfo.cpp2
-rw-r--r--src/modinfo.h8
-rw-r--r--src/profile.cpp11
3 files changed, 9 insertions, 12 deletions
diff --git a/src/modinfo.cpp b/src/modinfo.cpp
index b46a68ab..254fbda3 100644
--- a/src/modinfo.cpp
+++ b/src/modinfo.cpp
@@ -52,7 +52,7 @@ using namespace MOShared;
const std::set<unsigned int> ModInfo::s_EmptySet;
std::vector<ModInfo::Ptr> ModInfo::s_Collection;
ModInfo::Ptr ModInfo::s_Overwrite;
-std::map<QString, unsigned int> ModInfo::s_ModsByName;
+std::map<QString, unsigned int, ModNameCompare> ModInfo::s_ModsByName;
std::map<std::pair<QString, int>, std::vector<unsigned int>> ModInfo::s_ModsByModID;
int ModInfo::s_NextID;
QMutex ModInfo::s_Mutex(QMutex::Recursive);
diff --git a/src/modinfo.h b/src/modinfo.h
index 634ea900..f18bd347 100644
--- a/src/modinfo.h
+++ b/src/modinfo.h
@@ -43,6 +43,12 @@ class QDateTime;
namespace MOBase { class IPluginGame; }
namespace MOShared { class DirectoryEntry; }
+struct ModNameCompare {
+ bool operator()(const QString& lhs, const QString& rhs) const {
+ return QString::compare(lhs, rhs, Qt::CaseInsensitive) < 0;
+ }
+};
+
/**
* @brief Represents meta information about a single mod.
*
@@ -989,7 +995,7 @@ protected:
static QMutex s_Mutex;
static std::vector<ModInfo::Ptr> s_Collection;
static ModInfo::Ptr s_Overwrite;
- static std::map<QString, unsigned int> s_ModsByName;
+ static std::map<QString, unsigned int, ModNameCompare> s_ModsByName;
static std::map<std::pair<QString, int>, std::vector<unsigned int>> s_ModsByModID;
static int s_NextID;
diff --git a/src/profile.cpp b/src/profile.cpp
index 5a71cacb..3cc1a2a3 100644
--- a/src/profile.cpp
+++ b/src/profile.cpp
@@ -410,18 +410,9 @@ void Profile::refreshModStatus()
} else {
namesRead.insert(lookupName);
}
- unsigned int modIndex = ModInfo::findMod(
- [lookupName](ModInfo::Ptr info) {
- return info->name().compare(lookupName, Qt::CaseInsensitive) == 0;
- }
- );
+ unsigned int modIndex = ModInfo::getIndex(lookupName);
if (modIndex != UINT_MAX) {
ModInfo::Ptr info = ModInfo::getByIndex(modIndex);
- if (info->name().compare(lookupName) != 0) {
- // name in modlist.txt doesn't match case of actual folder
- // need to rewrite the modlist to fix this
- modStatusModified = true;
- }
if ((modIndex < m_ModStatus.size())
&& (info->getFixedPriority() == INT_MIN)) {
m_ModStatus[modIndex].m_Enabled = enabled;