From 38ee6d285d5ce80a9273bda4b0e739f375d3fb90 Mon Sep 17 00:00:00 2001 From: Petr Mikheev Date: Sun, 17 Jul 2022 12:19:19 +0200 Subject: [PATCH] Use std::string_view in VFS::Manager --- components/vfs/manager.cpp | 22 +++++++++++----------- components/vfs/manager.hpp | 12 ++++++------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/components/vfs/manager.cpp b/components/vfs/manager.cpp index bd7418d4b5..143f765616 100644 --- a/components/vfs/manager.cpp +++ b/components/vfs/manager.cpp @@ -57,9 +57,9 @@ namespace VFS archive->listResources(mIndex, mStrict ? &strict_normalize_char : &nonstrict_normalize_char); } - Files::IStreamPtr Manager::get(const std::string &name) const + Files::IStreamPtr Manager::get(std::string_view name) const { - std::string normalized = name; + std::string normalized(name); normalize_path(normalized, mStrict); return getNormalized(normalized); @@ -73,24 +73,24 @@ namespace VFS return found->second->open(); } - bool Manager::exists(const std::string &name) const + bool Manager::exists(std::string_view name) const { - std::string normalized = name; + std::string normalized(name); normalize_path(normalized, mStrict); return mIndex.find(normalized) != mIndex.end(); } - std::string Manager::normalizeFilename(const std::string& name) const + std::string Manager::normalizeFilename(std::string_view name) const { - std::string result = name; + std::string result(name); normalize_path(result, mStrict); return result; } - std::string Manager::getArchive(const std::string& name) const + std::string Manager::getArchive(std::string_view name) const { - std::string normalized = name; + std::string normalized(name); normalize_path(normalized, mStrict); for(auto it = mArchives.rbegin(); it != mArchives.rend(); ++it) { @@ -100,9 +100,9 @@ namespace VFS return {}; } - std::string Manager::getAbsoluteFileName(const std::string& name) const + std::string Manager::getAbsoluteFileName(std::string_view name) const { - std::string normalized = name; + std::string normalized(name); normalize_path(normalized, mStrict); std::map::const_iterator found = mIndex.find(normalized); @@ -119,7 +119,7 @@ namespace VFS } } - Manager::RecursiveDirectoryRange Manager::getRecursiveDirectoryIterator(const std::string& path) const + Manager::RecursiveDirectoryRange Manager::getRecursiveDirectoryIterator(std::string_view path) const { if (path.empty()) return { mIndex.begin(), mIndex.end() }; diff --git a/components/vfs/manager.hpp b/components/vfs/manager.hpp index bb1ee6ad39..501b6d7e13 100644 --- a/components/vfs/manager.hpp +++ b/components/vfs/manager.hpp @@ -66,34 +66,34 @@ namespace VFS /// Does a file with this name exist? /// @note May be called from any thread once the index has been built. - bool exists(const std::string& name) const; + bool exists(std::string_view name) const; /// Normalize the given filename, making slashes/backslashes consistent, and lower-casing if mStrict is false. /// @note May be called from any thread once the index has been built. - [[nodiscard]] std::string normalizeFilename(const std::string& name) const; + [[nodiscard]] std::string normalizeFilename(std::string_view name) const; /// Retrieve a file by name. /// @note Throws an exception if the file can not be found. /// @note May be called from any thread once the index has been built. - Files::IStreamPtr get(const std::string& name) const; + Files::IStreamPtr get(std::string_view name) const; /// Retrieve a file by name (name is already normalized). /// @note Throws an exception if the file can not be found. /// @note May be called from any thread once the index has been built. Files::IStreamPtr getNormalized(const std::string& normalizedName) const; - std::string getArchive(const std::string& name) const; + std::string getArchive(std::string_view name) const; /// Recursivly iterate over the elements of the given path /// In practice it return all files of the VFS starting with the given path /// @note the path is normalized /// @note May be called from any thread once the index has been built. - RecursiveDirectoryRange getRecursiveDirectoryIterator(const std::string& path) const; + RecursiveDirectoryRange getRecursiveDirectoryIterator(std::string_view path) const; /// Retrieve the absolute path to the file /// @note Throws an exception if the file can not be found. /// @note May be called from any thread once the index has been built. - std::string getAbsoluteFileName(const std::string& name) const; + std::string getAbsoluteFileName(std::string_view name) const; private: bool mStrict;