From 3ef0db4cca1971ed1552c0314e0039dac792d2e5 Mon Sep 17 00:00:00 2001 From: RJ <122295667+Liderate@users.noreply.github.com> Date: Fri, 23 May 2025 03:15:43 -0400 Subject: 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 --- src/directoryrefresher.cpp | 32 ++++++++++++++++++-------------- src/mainwindow.cpp | 16 +++++++++++----- 2 files changed, 29 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/directoryrefresher.cpp b/src/directoryrefresher.cpp index e2e05b2c..9afbfca8 100644 --- a/src/directoryrefresher.cpp +++ b/src/directoryrefresher.cpp @@ -328,7 +328,8 @@ struct ModThread int prio = -1; std::vector archives; std::set enabledArchives; - DirectoryStats* stats = nullptr; + std::vector* loadOrder = nullptr; + DirectoryStats* stats = nullptr; env::DirectoryWalker walker; std::condition_variable cv; @@ -356,18 +357,8 @@ struct ModThread ds->addFromOrigin(walker, modName, path, prio, *stats); if (Settings::instance().archiveParsing()) { - QStringList loadOrder; - auto gamePlugins = gameFeatures->gameFeature(); - if (gamePlugins) { - loadOrder = gamePlugins->getLoadOrder(); - } - - std::vector lo; - for (auto&& s : loadOrder) { - lo.push_back(s.toStdWString()); - } - - ds->addFromAllBSAs(modName, path, prio, archives, enabledArchives, lo, *stats); + ds->addFromAllBSAs(modName, path, prio, archives, enabledArchives, *loadOrder, + *stats); } if (progress) { @@ -400,6 +391,18 @@ void DirectoryRefresher::addMultipleModsFilesToStructure( log::debug("refresher: using {} threads", m_threadCount); g_threads.setMax(m_threadCount); + std::vector loadOrder; + if (Settings::instance().archiveParsing()) { + auto gamePlugins = m_Core.gameFeatures().gameFeature(); + if (gamePlugins) { + QStringList lo = gamePlugins->getLoadOrder(); + loadOrder.reserve(lo.size()); + for (auto&& s : lo) { + loadOrder.push_back(s.toStdWString()); + } + } + } + for (std::size_t i = 0; i < entries.size(); ++i) { const auto& e = entries[i]; const int prio = e.priority + 1; @@ -436,7 +439,8 @@ void DirectoryRefresher::addMultipleModsFilesToStructure( mt.enabledArchives.insert(a.toStdWString()); } - mt.stats = &stats[i]; + mt.loadOrder = &loadOrder; + mt.stats = &stats[i]; mt.wakeup(); } diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index bdc40f68..c8847534 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1919,12 +1919,18 @@ void MainWindow::updateBSAList(const QStringList& defaultArchives, fileName.endsWith(".esl", Qt::CaseInsensitive); }); + QList> pluginNamePairs; + pluginNamePairs.reserve(plugins.size()); + for (const QString& pluginName : plugins) { + QFileInfo pluginInfo(pluginName); + pluginNamePairs.append( + std::make_pair(pluginInfo.completeBaseName(), pluginInfo.fileName())); + } + auto hasAssociatedPlugin = [&](const QString& bsaName) -> bool { - for (const QString& pluginName : plugins) { - QFileInfo pluginInfo(pluginName); - if (bsaName.startsWith(QFileInfo(pluginName).completeBaseName(), - Qt::CaseInsensitive) && - (m_OrganizerCore.pluginList()->state(pluginInfo.fileName()) == + for (const auto& [completeBaseName, fileName] : pluginNamePairs) { + if (bsaName.startsWith(completeBaseName, Qt::CaseInsensitive) && + (m_OrganizerCore.pluginList()->state(fileName) == IPluginList::STATE_ACTIVE)) { return true; } -- cgit v1.3.1