Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

PluginList::refresh speedup #2046

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 56 additions & 53 deletions src/pluginlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,82 +182,85 @@ void PluginList::refresh(const QString& profileName,
gamePlugins ? gamePlugins->lightPluginsAreSupported() : false;
const bool overridePluginsAreSupported =
gamePlugins ? gamePlugins->overridePluginsAreSupported() : false;
const bool loadOrderMechanismNone =
m_GamePlugin->loadOrderMechanism() == IPluginGame::LoadOrderMechanism::None;

m_CurrentProfile = profileName;

QStringList availablePlugins;
std::vector<std::pair<QString, FileEntryPtr>> availablePlugins;
Holt59 marked this conversation as resolved.
Show resolved Hide resolved
QStringList archiveCandidates;

std::vector<FileEntryPtr> files = baseDirectory.getFiles();
for (FileEntryPtr current : files) {
for (FileEntryPtr current : baseDirectory.getFiles()) {
if (current.get() == nullptr) {
continue;
}
QString filename = ToQString(current->getName());
const QString& filename = ToQString(current->getName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not important, but for future reference, the change to this line does nothing. ToQString returns a QString, not a const QString&, so a QString has to be constructed in this stack frame anyway. There's no copy happening in the old or new version due to copy elision.


if (filename.endsWith(".esp", Qt::CaseInsensitive) ||
filename.endsWith(".esm", Qt::CaseInsensitive) ||
filename.endsWith(".esl", Qt::CaseInsensitive)) {
availablePlugins.emplace_back(filename, current);
} else if (filename.endsWith(".bsa", Qt::CaseInsensitive) ||
filename.endsWith("ba2", Qt::CaseInsensitive)) {
archiveCandidates.append(filename);
}
}

availablePlugins.append(filename);
for (const auto& [filename, current] : availablePlugins) {
if (m_ESPsByName.contains(filename)) {
continue;
}

if (m_ESPsByName.find(filename) != m_ESPsByName.end()) {
continue;
}
bool forceLoaded = Settings::instance().game().forceEnableCoreFiles() &&
primaryPlugins.contains(filename, Qt::CaseInsensitive);
bool forceEnabled = enabledPlugins.contains(filename, Qt::CaseInsensitive);
bool forceDisabled = loadOrderMechanismNone && !forceLoaded && !forceEnabled;
if (!lightPluginsAreSupported && filename.endsWith(".esl")) {
forceDisabled = true;
}

bool forceLoaded = Settings::instance().game().forceEnableCoreFiles() &&
primaryPlugins.contains(filename, Qt::CaseInsensitive);
bool forceEnabled = enabledPlugins.contains(filename, Qt::CaseInsensitive);
bool forceDisabled =
m_GamePlugin->loadOrderMechanism() == IPluginGame::LoadOrderMechanism::None &&
!forceLoaded && !forceEnabled;
if (!lightPluginsAreSupported && filename.endsWith(".esl")) {
forceDisabled = true;
}
bool archive = false;
try {
FilesOrigin& origin = baseDirectory.getOriginByID(current->getOrigin(archive));

bool archive = false;
try {
FilesOrigin& origin = baseDirectory.getOriginByID(current->getOrigin(archive));

// name without extension
QString baseName = QFileInfo(filename).completeBaseName();

QString iniPath = baseName + ".ini";
bool hasIni = baseDirectory.findFile(ToWString(iniPath)).get() != nullptr;
std::set<QString> loadedArchives;
QString candidateName;
for (FileEntryPtr archiveCandidate : files) {
candidateName = ToQString(archiveCandidate->getName());
if (candidateName.startsWith(baseName, Qt::CaseInsensitive) &&
(candidateName.endsWith(".bsa", Qt::CaseInsensitive) ||
candidateName.endsWith(".ba2", Qt::CaseInsensitive))) {
loadedArchives.insert(candidateName);
}
}
// name without extension
QString baseName = QFileInfo(filename).completeBaseName();

QString originName = ToQString(origin.getName());
unsigned int modIndex = ModInfo::getIndex(originName);
if (modIndex != UINT_MAX) {
ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex);
originName = modInfo->name();
QString iniPath = baseName + ".ini";
bool hasIni = baseDirectory.findFile(ToWString(iniPath)).get() != nullptr;
std::set<QString> loadedArchives;
for (const auto& archiveName : archiveCandidates) {
if (archiveName.startsWith(baseName, Qt::CaseInsensitive)) {
loadedArchives.insert(archiveName);
}
}

m_ESPs.push_back(ESPInfo(filename, forceLoaded, forceEnabled, forceDisabled,
originName, ToQString(current->getFullPath()), hasIni,
loadedArchives, lightPluginsAreSupported,
overridePluginsAreSupported));
m_ESPs.rbegin()->priority = -1;
} catch (const std::exception& e) {
reportError(
tr("failed to update esp info for file %1 (source id: %2), error: %3")
.arg(filename)
.arg(current->getOrigin(archive))
.arg(e.what()));
QString originName = ToQString(origin.getName());
unsigned int modIndex = ModInfo::getIndex(originName);
if (modIndex != UINT_MAX) {
ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex);
originName = modInfo->name();
}

m_ESPs.emplace_back(ESPInfo(filename, forceLoaded, forceEnabled, forceDisabled,
Holt59 marked this conversation as resolved.
Show resolved Hide resolved
originName, ToQString(current->getFullPath()), hasIni,
loadedArchives, lightPluginsAreSupported,
overridePluginsAreSupported));
m_ESPs.rbegin()->priority = -1;
} catch (const std::exception& e) {
reportError(tr("failed to update esp info for file %1 (source id: %2), error: %3")
.arg(filename)
.arg(current->getOrigin(archive))
.arg(e.what()));
}
}

for (const auto& espName : m_ESPsByName) {
if (!availablePlugins.contains(espName.first, Qt::CaseInsensitive)) {
auto it = std::ranges::find_if(
availablePlugins, [&espName](const std::pair<QString, FileEntryPtr>& ele) {
return ele.first.compare(espName.first, Qt::CaseInsensitive) == 0;
});
if (it == availablePlugins.end()) {
m_ESPs[espName.second].name = "";
}
}
Expand Down
1 change: 1 addition & 0 deletions src/shared/directoryentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ int DirectoryEntry::anyOrigin() const
std::vector<FileEntryPtr> DirectoryEntry::getFiles() const
{
std::vector<FileEntryPtr> result;
result.reserve(m_Files.size());

for (auto iter = m_Files.begin(); iter != m_Files.end(); ++iter) {
result.push_back(m_FileRegister->getFile(iter->second));
Expand Down
Loading