From d100de27ee77fc98e1f3fa3dc6d2db0999da0a1a Mon Sep 17 00:00:00 2001 From: Liam Date: Sun, 7 May 2023 16:33:35 -0400 Subject: vfs_layered: avoid n^2 lookup in layeredfs building --- src/core/file_sys/vfs_layered.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/core') diff --git a/src/core/file_sys/vfs_layered.cpp b/src/core/file_sys/vfs_layered.cpp index da05dd395..3e6426afc 100644 --- a/src/core/file_sys/vfs_layered.cpp +++ b/src/core/file_sys/vfs_layered.cpp @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include #include #include "core/file_sys/vfs_layered.h" @@ -58,11 +59,13 @@ std::string LayeredVfsDirectory::GetFullPath() const { std::vector LayeredVfsDirectory::GetFiles() const { std::vector out; + std::set> out_names; + for (const auto& layer : dirs) { for (const auto& file : layer->GetFiles()) { - if (std::find_if(out.begin(), out.end(), [&file](const VirtualFile& comp) { - return comp->GetName() == file->GetName(); - }) == out.end()) { + auto file_name = file->GetName(); + if (!out_names.contains(file_name)) { + out_names.emplace(std::move(file_name)); out.push_back(file); } } -- cgit v1.2.3