From 149c593d89776d8b5172b4d719a08afe68e6d188 Mon Sep 17 00:00:00 2001 From: Eladash Date: Mon, 25 Oct 2021 16:50:27 +0300 Subject: [PATCH] Make fs::get_parent_dir/fs::pending_file use string_view as argument --- Utilities/File.cpp | 6 +++--- Utilities/File.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Utilities/File.cpp b/Utilities/File.cpp index a98fb8bae2..2ac13f7b2b 100644 --- a/Utilities/File.cpp +++ b/Utilities/File.cpp @@ -384,7 +384,7 @@ shared_ptr fs::set_virtual_device(const std::string& name, shar return get_device_manager().set_device(name, std::move(device)); } -std::string fs::get_parent_dir(const std::string& path, u32 levels) +std::string fs::get_parent_dir(std::string_view path, u32 levels) { std::string_view result = path; @@ -1981,11 +1981,11 @@ fs::file fs::make_gather(std::vector files) return result; } -fs::pending_file::pending_file(const std::string& path) +fs::pending_file::pending_file(std::string_view path) { do { - m_path = fmt::format(u8"%s/$%s.%s.tmp", get_parent_dir(path), std::string_view(path).substr(path.find_last_of(fs::delim) + 1), fmt::base57(utils::get_unique_tsc())); + m_path = fmt::format(u8"%s/$%s.%s.tmp", get_parent_dir(path), path.substr(path.find_last_of(fs::delim) + 1), fmt::base57(utils::get_unique_tsc())); if (file.open(m_path, fs::create + fs::write + fs::read + fs::excl)) { diff --git a/Utilities/File.h b/Utilities/File.h index a210d2216d..cee48f95d9 100644 --- a/Utilities/File.h +++ b/Utilities/File.h @@ -159,7 +159,7 @@ namespace fs shared_ptr set_virtual_device(const std::string& name, shared_ptr device); // Try to get parent directory (returns empty string on failure) - std::string get_parent_dir(const std::string& path, u32 levels = 1); + std::string get_parent_dir(std::string_view path, u32 levels = 1); // Get file information bool stat(const std::string& path, stat_t& info); @@ -637,7 +637,7 @@ namespace fs // This is meant to modify files atomically, overwriting is likely bool commit(bool overwrite = true); - pending_file(const std::string& path); + pending_file(std::string_view path); pending_file(const pending_file&) = delete; pending_file& operator=(const pending_file&) = delete; ~pending_file();