diff options
author | Liam <byteslice@airmail.cc> | 2023-05-07 07:19:13 +0200 |
---|---|---|
committer | Liam <byteslice@airmail.cc> | 2023-05-07 22:50:35 +0200 |
commit | 5792a72c29dbc7af6a28603136206e97ef58943d (patch) | |
tree | 1a78974bcfbedcab5e94f894b6330ada9edb98f0 /src/core/file_sys/vfs_vector.cpp | |
parent | Merge pull request #10081 from Kelebek1/copy_overlap_tick (diff) | |
download | yuzu-5792a72c29dbc7af6a28603136206e97ef58943d.tar yuzu-5792a72c29dbc7af6a28603136206e97ef58943d.tar.gz yuzu-5792a72c29dbc7af6a28603136206e97ef58943d.tar.bz2 yuzu-5792a72c29dbc7af6a28603136206e97ef58943d.tar.lz yuzu-5792a72c29dbc7af6a28603136206e97ef58943d.tar.xz yuzu-5792a72c29dbc7af6a28603136206e97ef58943d.tar.zst yuzu-5792a72c29dbc7af6a28603136206e97ef58943d.zip |
Diffstat (limited to 'src/core/file_sys/vfs_vector.cpp')
-rw-r--r-- | src/core/file_sys/vfs_vector.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/core/file_sys/vfs_vector.cpp b/src/core/file_sys/vfs_vector.cpp index 251d9d7c9..af1df4c51 100644 --- a/src/core/file_sys/vfs_vector.cpp +++ b/src/core/file_sys/vfs_vector.cpp @@ -67,6 +67,23 @@ VectorVfsDirectory::VectorVfsDirectory(std::vector<VirtualFile> files_, VectorVfsDirectory::~VectorVfsDirectory() = default; +VirtualFile VectorVfsDirectory::GetFile(std::string_view file_name) const { + if (!optimized_file_index_built) { + optimized_file_index.clear(); + for (size_t i = 0; i < files.size(); i++) { + optimized_file_index.emplace(files[i]->GetName(), i); + } + optimized_file_index_built = true; + } + + const auto it = optimized_file_index.find(file_name); + if (it != optimized_file_index.end()) { + return files[it->second]; + } + + return nullptr; +} + std::vector<VirtualFile> VectorVfsDirectory::GetFiles() const { return files; } @@ -107,6 +124,7 @@ bool VectorVfsDirectory::DeleteSubdirectory(std::string_view subdir_name) { } bool VectorVfsDirectory::DeleteFile(std::string_view file_name) { + optimized_file_index_built = false; return FindAndRemoveVectorElement(files, file_name); } @@ -124,6 +142,7 @@ VirtualFile VectorVfsDirectory::CreateFile(std::string_view file_name) { } void VectorVfsDirectory::AddFile(VirtualFile file) { + optimized_file_index_built = false; files.push_back(std::move(file)); } |