forked from ShuriZma/suyu
1
0
Fork 0

Merge pull request #754 from lioncash/part

partition_filesystem, vfs_real: Minor changes
This commit is contained in:
bunnei 2018-07-21 11:38:52 -07:00 committed by GitHub
commit 0f20fa5a1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 8 deletions

View File

@ -2,7 +2,12 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <algorithm>
#include <cstddef>
#include <cstring>
#include <iterator>
#include <utility> #include <utility>
#include "common/file_util.h" #include "common/file_util.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/file_sys/partition_filesystem.h" #include "core/file_sys/partition_filesystem.h"
@ -99,14 +104,15 @@ void PartitionFilesystem::PrintDebugInfo() const {
} }
bool PartitionFilesystem::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { bool PartitionFilesystem::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) {
auto iter = std::find(pfs_files.begin(), pfs_files.end(), file); const auto iter = std::find(pfs_files.begin(), pfs_files.end(), file);
if (iter == pfs_files.end()) if (iter == pfs_files.end())
return false; return false;
pfs_files[iter - pfs_files.begin()] = pfs_files.back(); const std::ptrdiff_t offset = std::distance(pfs_files.begin(), iter);
pfs_files[offset] = pfs_files.back();
pfs_files.pop_back(); pfs_files.pop_back();
pfs_dirs.emplace_back(dir); pfs_dirs.emplace_back(std::move(dir));
return true; return true;
} }

View File

@ -2,6 +2,11 @@
// Licensed under GPLv2 or any later version // Licensed under GPLv2 or any later version
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <algorithm>
#include <cstddef>
#include <iterator>
#include <utility>
#include "common/common_paths.h" #include "common/common_paths.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/file_sys/vfs_real.h" #include "core/file_sys/vfs_real.h"
@ -104,11 +109,11 @@ RealVfsDirectory::RealVfsDirectory(const std::string& path_, Mode perms_)
} }
std::vector<std::shared_ptr<VfsFile>> RealVfsDirectory::GetFiles() const { std::vector<std::shared_ptr<VfsFile>> RealVfsDirectory::GetFiles() const {
return std::vector<std::shared_ptr<VfsFile>>(files); return files;
} }
std::vector<std::shared_ptr<VfsDirectory>> RealVfsDirectory::GetSubdirectories() const { std::vector<std::shared_ptr<VfsDirectory>> RealVfsDirectory::GetSubdirectories() const {
return std::vector<std::shared_ptr<VfsDirectory>>(subdirectories); return subdirectories;
} }
bool RealVfsDirectory::IsWritable() const { bool RealVfsDirectory::IsWritable() const {
@ -163,14 +168,15 @@ bool RealVfsDirectory::Rename(const std::string& name) {
} }
bool RealVfsDirectory::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { bool RealVfsDirectory::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) {
auto iter = std::find(files.begin(), files.end(), file); const auto iter = std::find(files.begin(), files.end(), file);
if (iter == files.end()) if (iter == files.end())
return false; return false;
files[iter - files.begin()] = files.back(); const std::ptrdiff_t offset = std::distance(files.begin(), iter);
files[offset] = files.back();
files.pop_back(); files.pop_back();
subdirectories.emplace_back(dir); subdirectories.emplace_back(std::move(dir));
return true; return true;
} }