forked from suyu/suyu
partition_filesystem, vfs_real: Use std::distance() instead of subtraction
This is a little bit more self-documenting on what is being done here.
This commit is contained in:
parent
8afc21f175
commit
2b91386e15
2 changed files with 10 additions and 4 deletions
|
@ -2,7 +2,9 @@
|
||||||
// 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 <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,11 +101,12 @@ 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(dir);
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
// 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 <iterator>
|
||||||
|
|
||||||
#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"
|
||||||
|
@ -163,11 +165,12 @@ 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(dir);
|
||||||
|
|
Loading…
Reference in a new issue