diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/file_sys/partition_filesystem.cpp | 12 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_real.cpp | 16 |
2 files changed, 20 insertions, 8 deletions
diff --git a/src/core/file_sys/partition_filesystem.cpp b/src/core/file_sys/partition_filesystem.cpp index 7ccca1089..8d2bd9f6b 100644 --- a/src/core/file_sys/partition_filesystem.cpp +++ b/src/core/file_sys/partition_filesystem.cpp | |||
| @@ -2,7 +2,12 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 6 | #include <cstddef> | ||
| 7 | #include <cstring> | ||
| 8 | #include <iterator> | ||
| 5 | #include <utility> | 9 | #include <utility> |
| 10 | |||
| 6 | #include "common/file_util.h" | 11 | #include "common/file_util.h" |
| 7 | #include "common/logging/log.h" | 12 | #include "common/logging/log.h" |
| 8 | #include "core/file_sys/partition_filesystem.h" | 13 | #include "core/file_sys/partition_filesystem.h" |
| @@ -99,14 +104,15 @@ void PartitionFilesystem::PrintDebugInfo() const { | |||
| 99 | } | 104 | } |
| 100 | 105 | ||
| 101 | bool PartitionFilesystem::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { | 106 | bool PartitionFilesystem::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { |
| 102 | auto iter = std::find(pfs_files.begin(), pfs_files.end(), file); | 107 | const auto iter = std::find(pfs_files.begin(), pfs_files.end(), file); |
| 103 | if (iter == pfs_files.end()) | 108 | if (iter == pfs_files.end()) |
| 104 | return false; | 109 | return false; |
| 105 | 110 | ||
| 106 | pfs_files[iter - pfs_files.begin()] = pfs_files.back(); | 111 | const std::ptrdiff_t offset = std::distance(pfs_files.begin(), iter); |
| 112 | pfs_files[offset] = pfs_files.back(); | ||
| 107 | pfs_files.pop_back(); | 113 | pfs_files.pop_back(); |
| 108 | 114 | ||
| 109 | pfs_dirs.emplace_back(dir); | 115 | pfs_dirs.emplace_back(std::move(dir)); |
| 110 | 116 | ||
| 111 | return true; | 117 | return true; |
| 112 | } | 118 | } |
diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp index 22c858e0d..f27fb1f2a 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp | |||
| @@ -2,6 +2,11 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 6 | #include <cstddef> | ||
| 7 | #include <iterator> | ||
| 8 | #include <utility> | ||
| 9 | |||
| 5 | #include "common/common_paths.h" | 10 | #include "common/common_paths.h" |
| 6 | #include "common/logging/log.h" | 11 | #include "common/logging/log.h" |
| 7 | #include "core/file_sys/vfs_real.h" | 12 | #include "core/file_sys/vfs_real.h" |
| @@ -104,11 +109,11 @@ RealVfsDirectory::RealVfsDirectory(const std::string& path_, Mode perms_) | |||
| 104 | } | 109 | } |
| 105 | 110 | ||
| 106 | std::vector<std::shared_ptr<VfsFile>> RealVfsDirectory::GetFiles() const { | 111 | std::vector<std::shared_ptr<VfsFile>> RealVfsDirectory::GetFiles() const { |
| 107 | return std::vector<std::shared_ptr<VfsFile>>(files); | 112 | return files; |
| 108 | } | 113 | } |
| 109 | 114 | ||
| 110 | std::vector<std::shared_ptr<VfsDirectory>> RealVfsDirectory::GetSubdirectories() const { | 115 | std::vector<std::shared_ptr<VfsDirectory>> RealVfsDirectory::GetSubdirectories() const { |
| 111 | return std::vector<std::shared_ptr<VfsDirectory>>(subdirectories); | 116 | return subdirectories; |
| 112 | } | 117 | } |
| 113 | 118 | ||
| 114 | bool RealVfsDirectory::IsWritable() const { | 119 | bool RealVfsDirectory::IsWritable() const { |
| @@ -163,14 +168,15 @@ bool RealVfsDirectory::Rename(const std::string& name) { | |||
| 163 | } | 168 | } |
| 164 | 169 | ||
| 165 | bool RealVfsDirectory::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { | 170 | bool RealVfsDirectory::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { |
| 166 | auto iter = std::find(files.begin(), files.end(), file); | 171 | const auto iter = std::find(files.begin(), files.end(), file); |
| 167 | if (iter == files.end()) | 172 | if (iter == files.end()) |
| 168 | return false; | 173 | return false; |
| 169 | 174 | ||
| 170 | files[iter - files.begin()] = files.back(); | 175 | const std::ptrdiff_t offset = std::distance(files.begin(), iter); |
| 176 | files[offset] = files.back(); | ||
| 171 | files.pop_back(); | 177 | files.pop_back(); |
| 172 | 178 | ||
| 173 | subdirectories.emplace_back(dir); | 179 | subdirectories.emplace_back(std::move(dir)); |
| 174 | 180 | ||
| 175 | return true; | 181 | return true; |
| 176 | } | 182 | } |