From cec9e9b811b18810ceabaddc4a20d575993e046b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 2 Aug 2018 11:36:01 -0400 Subject: vfs_vector: Avoid unnecessary copies where applicable The lambda elements should be taken by const reference here, and we can move the virtual directory passed to ReplaceFileWithSubdirectory() --- src/core/file_sys/vfs_vector.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/core/file_sys/vfs_vector.cpp b/src/core/file_sys/vfs_vector.cpp index 4c6337e3a..e3f5026a8 100644 --- a/src/core/file_sys/vfs_vector.cpp +++ b/src/core/file_sys/vfs_vector.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include "core/file_sys/vfs_vector.h" namespace FileSys { @@ -31,13 +32,15 @@ bool VectorVfsDirectory::IsReadable() const { std::string VectorVfsDirectory::GetName() const { return name; } + std::shared_ptr VectorVfsDirectory::GetParentDirectory() const { return parent; } template static bool FindAndRemoveVectorElement(std::vector& vec, std::string_view name) { - auto iter = std::find_if(vec.begin(), vec.end(), [name](T e) { return e->GetName() == name; }); + auto iter = + std::find_if(vec.begin(), vec.end(), [name](const T& e) { return e->GetName() == name; }); if (iter == vec.end()) return false; auto old_size = vec.size(); @@ -77,7 +80,7 @@ void VectorVfsDirectory::AddDirectory(VirtualDir dir) { bool VectorVfsDirectory::ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) { if (!DeleteFile(file->GetName())) return false; - dirs.emplace_back(dir); + dirs.emplace_back(std::move(dir)); return true; } } // namespace FileSys -- cgit v1.2.3