mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-12-24 11:35:31 +08:00
libstdc++: Fix inefficiency in filesystem::absolute [PR99876]
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.
This commit is contained in:
parent
952095bb05
commit
07b990ee23
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user