]> gcc.gnu.org Git - 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>
Sat, 28 Aug 2021 10:52:22 +0000 (11:52 +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.

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

index 0e2d952673fd04ed4edb5adf6d639708ff1e0491..2eac9977785f007f2aa2fbc237818e68ad027dfe 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
This page took 0.059 seconds and 5 git commands to generate.