diff options
| author | 2023-05-07 01:19:13 -0400 | |
|---|---|---|
| committer | 2023-05-07 16:50:35 -0400 | |
| commit | 5792a72c29dbc7af6a28603136206e97ef58943d (patch) | |
| tree | 1a78974bcfbedcab5e94f894b6330ada9edb98f0 /src | |
| parent | Merge pull request #10081 from Kelebek1/copy_overlap_tick (diff) | |
| download | yuzu-5792a72c29dbc7af6a28603136206e97ef58943d.tar.gz yuzu-5792a72c29dbc7af6a28603136206e97ef58943d.tar.xz yuzu-5792a72c29dbc7af6a28603136206e97ef58943d.zip | |
vfs_vector: avoid n^2 lookup in layeredfs building
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/file_sys/vfs_vector.cpp | 19 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_vector.h | 4 |
2 files changed, 23 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_, | |||
| 67 | 67 | ||
| 68 | VectorVfsDirectory::~VectorVfsDirectory() = default; | 68 | VectorVfsDirectory::~VectorVfsDirectory() = default; |
| 69 | 69 | ||
| 70 | VirtualFile VectorVfsDirectory::GetFile(std::string_view file_name) const { | ||
| 71 | if (!optimized_file_index_built) { | ||
| 72 | optimized_file_index.clear(); | ||
| 73 | for (size_t i = 0; i < files.size(); i++) { | ||
| 74 | optimized_file_index.emplace(files[i]->GetName(), i); | ||
| 75 | } | ||
| 76 | optimized_file_index_built = true; | ||
| 77 | } | ||
| 78 | |||
| 79 | const auto it = optimized_file_index.find(file_name); | ||
| 80 | if (it != optimized_file_index.end()) { | ||
| 81 | return files[it->second]; | ||
| 82 | } | ||
| 83 | |||
| 84 | return nullptr; | ||
| 85 | } | ||
| 86 | |||
| 70 | std::vector<VirtualFile> VectorVfsDirectory::GetFiles() const { | 87 | std::vector<VirtualFile> VectorVfsDirectory::GetFiles() const { |
| 71 | return files; | 88 | return files; |
| 72 | } | 89 | } |
| @@ -107,6 +124,7 @@ bool VectorVfsDirectory::DeleteSubdirectory(std::string_view subdir_name) { | |||
| 107 | } | 124 | } |
| 108 | 125 | ||
| 109 | bool VectorVfsDirectory::DeleteFile(std::string_view file_name) { | 126 | bool VectorVfsDirectory::DeleteFile(std::string_view file_name) { |
| 127 | optimized_file_index_built = false; | ||
| 110 | return FindAndRemoveVectorElement(files, file_name); | 128 | return FindAndRemoveVectorElement(files, file_name); |
| 111 | } | 129 | } |
| 112 | 130 | ||
| @@ -124,6 +142,7 @@ VirtualFile VectorVfsDirectory::CreateFile(std::string_view file_name) { | |||
| 124 | } | 142 | } |
| 125 | 143 | ||
| 126 | void VectorVfsDirectory::AddFile(VirtualFile file) { | 144 | void VectorVfsDirectory::AddFile(VirtualFile file) { |
| 145 | optimized_file_index_built = false; | ||
| 127 | files.push_back(std::move(file)); | 146 | files.push_back(std::move(file)); |
| 128 | } | 147 | } |
| 129 | 148 | ||
diff --git a/src/core/file_sys/vfs_vector.h b/src/core/file_sys/vfs_vector.h index bfedb6e42..c9955755b 100644 --- a/src/core/file_sys/vfs_vector.h +++ b/src/core/file_sys/vfs_vector.h | |||
| @@ -105,6 +105,7 @@ public: | |||
| 105 | VirtualDir parent = nullptr); | 105 | VirtualDir parent = nullptr); |
| 106 | ~VectorVfsDirectory() override; | 106 | ~VectorVfsDirectory() override; |
| 107 | 107 | ||
| 108 | VirtualFile GetFile(std::string_view file_name) const override; | ||
| 108 | std::vector<VirtualFile> GetFiles() const override; | 109 | std::vector<VirtualFile> GetFiles() const override; |
| 109 | std::vector<VirtualDir> GetSubdirectories() const override; | 110 | std::vector<VirtualDir> GetSubdirectories() const override; |
| 110 | bool IsWritable() const override; | 111 | bool IsWritable() const override; |
| @@ -126,6 +127,9 @@ private: | |||
| 126 | 127 | ||
| 127 | VirtualDir parent; | 128 | VirtualDir parent; |
| 128 | std::string name; | 129 | std::string name; |
| 130 | |||
| 131 | mutable std::map<std::string, size_t, std::less<>> optimized_file_index; | ||
| 132 | mutable bool optimized_file_index_built{}; | ||
| 129 | }; | 133 | }; |
| 130 | 134 | ||
| 131 | } // namespace FileSys | 135 | } // namespace FileSys |