]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix inefficiency in filesystem::absolute [PR99876]
authorJonathan Wakely <jwakely@redhat.com>
Fri, 27 Aug 2021 09:59:54 +0000 (10:59 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 12 Oct 2021 10:45:43 +0000 (11:45 +0100)
When the path is already absolute, the call to current_path() is
wasteful, because operator/ will ignore the left operand anyway.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

PR libstdc++/99876
* src/c++17/fs_ops.cc (fs::absolute): Call non-throwing form,
to avoid unnecessary current_path() call.

(cherry picked from commit 07b990ee23e0c7a92d362dbb25fd5d57d95eb8be)

libstdc++-v3/src/c++17/fs_ops.cc

index ceaf0291d64a9cf1604097dcb18962ade4b4fff2..acff0ff926e11672773c8f7bff8a4fa9af722d01 100644 (file)
@@ -65,19 +65,12 @@ namespace posix = std::filesystem::__gnu_posix;
 fs::path
 fs::absolute(const path& p)
 {
-#ifdef _GLIBCXX_FILESYSTEM_IS_WINDOWS
   error_code ec;
   path ret = absolute(p, ec);
   if (ec)
     _GLIBCXX_THROW_OR_ABORT(filesystem_error("cannot make absolute path", p,
                                             ec));
   return ret;
-#else
-  if (p.empty())
-    _GLIBCXX_THROW_OR_ABORT(filesystem_error("cannot make absolute path", p,
-         make_error_code(std::errc::invalid_argument)));
-  return current_path() / p;
-#endif
 }
 
 fs::path