From 398444e67635c158a20301d1a32a1c45bfdd4056 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 22 Jul 2018 01:23:29 -0400 Subject: file_util, vfs: Use std::string_view where applicable Avoids unnecessary construction of std::string instances where applicable. --- src/core/file_sys/vfs.h | 50 ++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'src/core/file_sys/vfs.h') diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h index db3c77eac..529c6c952 100644 --- a/src/core/file_sys/vfs.h +++ b/src/core/file_sys/vfs.h @@ -6,11 +6,11 @@ #include #include +#include #include #include #include "boost/optional.hpp" #include "common/common_types.h" -#include "common/file_util.h" namespace FileSys { struct VfsFile; @@ -112,7 +112,7 @@ struct VfsFile : NonCopyable { } // Renames the file to name. Returns whether or not the operation was successsful. - virtual bool Rename(const std::string& name) = 0; + virtual bool Rename(std::string_view name) = 0; }; // A class representing a directory in an abstract filesystem. @@ -121,27 +121,27 @@ struct VfsDirectory : NonCopyable { // Retrives the file located at path as if the current directory was root. Returns nullptr if // not found. - virtual std::shared_ptr GetFileRelative(const std::string& path) const; + virtual std::shared_ptr GetFileRelative(std::string_view path) const; // Calls GetFileRelative(path) on the root of the current directory. - virtual std::shared_ptr GetFileAbsolute(const std::string& path) const; + virtual std::shared_ptr GetFileAbsolute(std::string_view path) const; // Retrives the directory located at path as if the current directory was root. Returns nullptr // if not found. - virtual std::shared_ptr GetDirectoryRelative(const std::string& path) const; + virtual std::shared_ptr GetDirectoryRelative(std::string_view path) const; // Calls GetDirectoryRelative(path) on the root of the current directory. - virtual std::shared_ptr GetDirectoryAbsolute(const std::string& path) const; + virtual std::shared_ptr GetDirectoryAbsolute(std::string_view path) const; // Returns a vector containing all of the files in this directory. virtual std::vector> GetFiles() const = 0; // Returns the file with filename matching name. Returns nullptr if directory dosen't have a // file with name. - virtual std::shared_ptr GetFile(const std::string& name) const; + virtual std::shared_ptr GetFile(std::string_view name) const; // Returns a vector containing all of the subdirectories in this directory. virtual std::vector> GetSubdirectories() const = 0; // Returns the directory with name matching name. Returns nullptr if directory dosen't have a // directory with name. - virtual std::shared_ptr GetSubdirectory(const std::string& name) const; + virtual std::shared_ptr GetSubdirectory(std::string_view name) const; // Returns whether or not the directory can be written to. virtual bool IsWritable() const = 0; @@ -161,49 +161,49 @@ struct VfsDirectory : NonCopyable { // Creates a new subdirectory with name name. Returns a pointer to the new directory or nullptr // if the operation failed. - virtual std::shared_ptr CreateSubdirectory(const std::string& name) = 0; + virtual std::shared_ptr CreateSubdirectory(std::string_view name) = 0; // Creates a new file with name name. Returns a pointer to the new file or nullptr if the // operation failed. - virtual std::shared_ptr CreateFile(const std::string& name) = 0; + virtual std::shared_ptr CreateFile(std::string_view name) = 0; // Creates a new file at the path relative to this directory. Also creates directories if // they do not exist and is supported by this implementation. Returns nullptr on any failure. - virtual std::shared_ptr CreateFileRelative(const std::string& path); + virtual std::shared_ptr CreateFileRelative(std::string_view path); // Creates a new file at the path relative to root of this directory. Also creates directories // if they do not exist and is supported by this implementation. Returns nullptr on any failure. - virtual std::shared_ptr CreateFileAbsolute(const std::string& path); + virtual std::shared_ptr CreateFileAbsolute(std::string_view path); // Creates a new directory at the path relative to this directory. Also creates directories if // they do not exist and is supported by this implementation. Returns nullptr on any failure. - virtual std::shared_ptr CreateDirectoryRelative(const std::string& path); + virtual std::shared_ptr CreateDirectoryRelative(std::string_view path); // Creates a new directory at the path relative to root of this directory. Also creates // directories if they do not exist and is supported by this implementation. Returns nullptr on // any failure. - virtual std::shared_ptr CreateDirectoryAbsolute(const std::string& path); + virtual std::shared_ptr CreateDirectoryAbsolute(std::string_view path); // Deletes the subdirectory with name and returns true on success. - virtual bool DeleteSubdirectory(const std::string& name) = 0; + virtual bool DeleteSubdirectory(std::string_view name) = 0; // Deletes all subdirectories and files of subdirectory with name recirsively and then deletes // the subdirectory. Returns true on success. - virtual bool DeleteSubdirectoryRecursive(const std::string& name); + virtual bool DeleteSubdirectoryRecursive(std::string_view name); // Returnes whether or not the file with name name was deleted successfully. - virtual bool DeleteFile(const std::string& name) = 0; + virtual bool DeleteFile(std::string_view name) = 0; // Returns whether or not this directory was renamed to name. - virtual bool Rename(const std::string& name) = 0; + virtual bool Rename(std::string_view name) = 0; // Returns whether or not the file with name src was successfully copied to a new file with name // dest. - virtual bool Copy(const std::string& src, const std::string& dest); + virtual bool Copy(std::string_view src, std::string_view dest); // Interprets the file with name file instead as a directory of type directory. // The directory must have a constructor that takes a single argument of type // std::shared_ptr. Allows to reinterpret container files (i.e NCA, zip, XCI, etc) as a // subdirectory in one call. template - bool InterpretAsDirectory(const std::string& file) { + bool InterpretAsDirectory(std::string_view file) { auto file_p = GetFile(file); if (file_p == nullptr) return false; @@ -221,10 +221,10 @@ protected: struct ReadOnlyVfsDirectory : public VfsDirectory { bool IsWritable() const override; bool IsReadable() const override; - std::shared_ptr CreateSubdirectory(const std::string& name) override; - std::shared_ptr CreateFile(const std::string& name) override; - bool DeleteSubdirectory(const std::string& name) override; - bool DeleteFile(const std::string& name) override; - bool Rename(const std::string& name) override; + std::shared_ptr CreateSubdirectory(std::string_view name) override; + std::shared_ptr CreateFile(std::string_view name) override; + bool DeleteSubdirectory(std::string_view name) override; + bool DeleteFile(std::string_view name) override; + bool Rename(std::string_view name) override; }; } // namespace FileSys -- cgit v1.2.3