From a269fc988b00b0a416d9edb25bde4211e2a15f54 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 3 Apr 2020 16:11:46 +0200 Subject: [PATCH] fs/Charset: enable RVO in FixSeparators() --- src/fs/Charset.cxx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/fs/Charset.cxx b/src/fs/Charset.cxx index 0a89111e5..6b4ca9f0a 100644 --- a/src/fs/Charset.cxx +++ b/src/fs/Charset.cxx @@ -74,19 +74,21 @@ GetFSCharset() noexcept #endif } -static inline PathTraitsUTF8::string && -FixSeparators(PathTraitsUTF8::string &&s) +static inline PathTraitsUTF8::string +FixSeparators(const PathTraitsUTF8::string_view _s) { // For whatever reason GCC can't convert constexpr to value reference. // This leads to link errors when passing separators directly. auto to = PathTraitsUTF8::SEPARATOR; decltype(to) from = PathTraitsFS::SEPARATOR; + PathTraitsUTF8::string s(_s); + if (from != to) /* convert backslash to slash on WIN32 */ std::replace(s.begin(), s.end(), from, to); - return std::move(s); + return s; } PathTraitsUTF8::string @@ -99,7 +101,7 @@ PathToUTF8(PathTraitsFS::const_pointer path_fs) #ifdef _WIN32 const auto buffer = WideCharToMultiByte(CP_UTF8, path_fs); - return FixSeparators(PathTraitsUTF8::string(buffer)); + return FixSeparators(buffer); #else #ifdef HAVE_FS_CHARSET if (fs_converter == nullptr) @@ -108,7 +110,7 @@ PathToUTF8(PathTraitsFS::const_pointer path_fs) #ifdef HAVE_FS_CHARSET const auto buffer = fs_converter->ToUTF8(path_fs); - return FixSeparators(PathTraitsUTF8::string(buffer)); + return FixSeparators(buffer); #endif #endif }