Skip to content

Commit 3ef0db4

Browse files
authored
Speedup refresh when archive parsing is enabled and updateBSAList (#2239)
* Precompute load order for ModThreads * Precompute file infos for plugin association check --------- Co-authored-by: RJ <Liderate@users.noreply.github.com>
1 parent 15f3d2b commit 3ef0db4

File tree

2 files changed

+29
-19
lines changed

2 files changed

+29
-19
lines changed

src/directoryrefresher.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,8 @@ struct ModThread
328328
int prio = -1;
329329
std::vector<std::wstring> archives;
330330
std::set<std::wstring> enabledArchives;
331-
DirectoryStats* stats = nullptr;
331+
std::vector<std::wstring>* loadOrder = nullptr;
332+
DirectoryStats* stats = nullptr;
332333
env::DirectoryWalker walker;
333334

334335
std::condition_variable cv;
@@ -356,18 +357,8 @@ struct ModThread
356357
ds->addFromOrigin(walker, modName, path, prio, *stats);
357358

358359
if (Settings::instance().archiveParsing()) {
359-
QStringList loadOrder;
360-
auto gamePlugins = gameFeatures->gameFeature<GamePlugins>();
361-
if (gamePlugins) {
362-
loadOrder = gamePlugins->getLoadOrder();
363-
}
364-
365-
std::vector<std::wstring> lo;
366-
for (auto&& s : loadOrder) {
367-
lo.push_back(s.toStdWString());
368-
}
369-
370-
ds->addFromAllBSAs(modName, path, prio, archives, enabledArchives, lo, *stats);
360+
ds->addFromAllBSAs(modName, path, prio, archives, enabledArchives, *loadOrder,
361+
*stats);
371362
}
372363

373364
if (progress) {
@@ -400,6 +391,18 @@ void DirectoryRefresher::addMultipleModsFilesToStructure(
400391
log::debug("refresher: using {} threads", m_threadCount);
401392
g_threads.setMax(m_threadCount);
402393

394+
std::vector<std::wstring> loadOrder;
395+
if (Settings::instance().archiveParsing()) {
396+
auto gamePlugins = m_Core.gameFeatures().gameFeature<GamePlugins>();
397+
if (gamePlugins) {
398+
QStringList lo = gamePlugins->getLoadOrder();
399+
loadOrder.reserve(lo.size());
400+
for (auto&& s : lo) {
401+
loadOrder.push_back(s.toStdWString());
402+
}
403+
}
404+
}
405+
403406
for (std::size_t i = 0; i < entries.size(); ++i) {
404407
const auto& e = entries[i];
405408
const int prio = e.priority + 1;
@@ -436,7 +439,8 @@ void DirectoryRefresher::addMultipleModsFilesToStructure(
436439
mt.enabledArchives.insert(a.toStdWString());
437440
}
438441

439-
mt.stats = &stats[i];
442+
mt.loadOrder = &loadOrder;
443+
mt.stats = &stats[i];
440444

441445
mt.wakeup();
442446
}

src/mainwindow.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,12 +1919,18 @@ void MainWindow::updateBSAList(const QStringList& defaultArchives,
19191919
fileName.endsWith(".esl", Qt::CaseInsensitive);
19201920
});
19211921

1922+
QList<std::pair<QString, QString>> pluginNamePairs;
1923+
pluginNamePairs.reserve(plugins.size());
1924+
for (const QString& pluginName : plugins) {
1925+
QFileInfo pluginInfo(pluginName);
1926+
pluginNamePairs.append(
1927+
std::make_pair(pluginInfo.completeBaseName(), pluginInfo.fileName()));
1928+
}
1929+
19221930
auto hasAssociatedPlugin = [&](const QString& bsaName) -> bool {
1923-
for (const QString& pluginName : plugins) {
1924-
QFileInfo pluginInfo(pluginName);
1925-
if (bsaName.startsWith(QFileInfo(pluginName).completeBaseName(),
1926-
Qt::CaseInsensitive) &&
1927-
(m_OrganizerCore.pluginList()->state(pluginInfo.fileName()) ==
1931+
for (const auto& [completeBaseName, fileName] : pluginNamePairs) {
1932+
if (bsaName.startsWith(completeBaseName, Qt::CaseInsensitive) &&
1933+
(m_OrganizerCore.pluginList()->state(fileName) ==
19281934
IPluginList::STATE_ACTIVE)) {
19291935
return true;
19301936
}

0 commit comments

Comments
 (0)