2
1
Fork 0
mirror of https://github.com/yuzu-emu/yuzu.git synced 2024-07-04 23:31:19 +01:00

vfs_layered: avoid n^2 lookup in layeredfs building

This commit is contained in:
Liam 2023-05-07 16:33:35 -04:00
parent 5792a72c29
commit d100de27ee

View file

@ -2,6 +2,7 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <algorithm> #include <algorithm>
#include <set>
#include <utility> #include <utility>
#include "core/file_sys/vfs_layered.h" #include "core/file_sys/vfs_layered.h"
@ -58,11 +59,13 @@ std::string LayeredVfsDirectory::GetFullPath() const {
std::vector<VirtualFile> LayeredVfsDirectory::GetFiles() const { std::vector<VirtualFile> LayeredVfsDirectory::GetFiles() const {
std::vector<VirtualFile> out; std::vector<VirtualFile> out;
std::set<std::string, std::less<>> out_names;
for (const auto& layer : dirs) { for (const auto& layer : dirs) {
for (const auto& file : layer->GetFiles()) { for (const auto& file : layer->GetFiles()) {
if (std::find_if(out.begin(), out.end(), [&file](const VirtualFile& comp) { auto file_name = file->GetName();
return comp->GetName() == file->GetName(); if (!out_names.contains(file_name)) {
}) == out.end()) { out_names.emplace(std::move(file_name));
out.push_back(file); out.push_back(file);
} }
} }