From 2b91386e155ba9a9e8c06d7c90fe9710aecf8076 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 20 Jul 2018 22:14:59 -0400 Subject: partition_filesystem, vfs_real: Use std::distance() instead of subtraction This is a little bit more self-documenting on what is being done here. --- src/core/file_sys/partition_filesystem.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/core/file_sys/partition_filesystem.cpp') diff --git a/src/core/file_sys/partition_filesystem.cpp b/src/core/file_sys/partition_filesystem.cpp index 7ccca1089..fc37a40cc 100644 --- a/src/core/file_sys/partition_filesystem.cpp +++ b/src/core/file_sys/partition_filesystem.cpp @@ -2,7 +2,9 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include + #include "common/file_util.h" #include "common/logging/log.h" #include "core/file_sys/partition_filesystem.h" @@ -99,11 +101,12 @@ void PartitionFilesystem::PrintDebugInfo() const { } 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()) 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_dirs.emplace_back(dir); -- cgit v1.2.3 From d36e327ba62fc853d75c413fd30ba38385dfa210 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 20 Jul 2018 22:23:56 -0400 Subject: partition_filesystem, vfs_real: Use std::move in ReplaceFileWithSubdirectory() where applicable Avoids unnecessary atomic increment and decrement operations. --- src/core/file_sys/partition_filesystem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/core/file_sys/partition_filesystem.cpp') diff --git a/src/core/file_sys/partition_filesystem.cpp b/src/core/file_sys/partition_filesystem.cpp index fc37a40cc..c523a605a 100644 --- a/src/core/file_sys/partition_filesystem.cpp +++ b/src/core/file_sys/partition_filesystem.cpp @@ -109,7 +109,7 @@ bool PartitionFilesystem::ReplaceFileWithSubdirectory(VirtualFile file, VirtualD pfs_files[offset] = pfs_files.back(); pfs_files.pop_back(); - pfs_dirs.emplace_back(dir); + pfs_dirs.emplace_back(std::move(dir)); return true; } -- cgit v1.2.3 From ec71915ede4cd1322ce1781b2a4545dfd46a0abf Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 20 Jul 2018 22:28:35 -0400 Subject: partition_filesystem, vfs_real: Add missing standard includes --- src/core/file_sys/partition_filesystem.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/core/file_sys/partition_filesystem.cpp') diff --git a/src/core/file_sys/partition_filesystem.cpp b/src/core/file_sys/partition_filesystem.cpp index c523a605a..8d2bd9f6b 100644 --- a/src/core/file_sys/partition_filesystem.cpp +++ b/src/core/file_sys/partition_filesystem.cpp @@ -2,6 +2,9 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include +#include +#include #include #include -- cgit v1.2.3