Commit e5ccb10a by Jonathan Wakely Committed by Jonathan Wakely

Optimize filesystem::path::parent_path()

Parsing a complete string is more efficient than appending each
component one-by-one.

	* src/c++17/fs_path.cc (path::parent_path()): Create whole path at
	once instead of building it iteratively.

From-SVN: r271754
parent e800d6dc
2019-05-29 Jonathan Wakely <jwakely@redhat.com> 2019-05-29 Jonathan Wakely <jwakely@redhat.com>
* src/c++17/fs_path.cc (path::parent_path()): Create whole path at
once instead of building it iteratively.
* testsuite/util/testsuite_api.h: Remove names of unused parameters. * testsuite/util/testsuite_api.h: Remove names of unused parameters.
PR libstdc++/85494 use rdseed and rand_s in std::random_device PR libstdc++/85494 use rdseed and rand_s in std::random_device
......
...@@ -1523,11 +1523,9 @@ path::parent_path() const ...@@ -1523,11 +1523,9 @@ path::parent_path() const
__ret = *this; __ret = *this;
else if (_M_cmpts.size() >= 2) else if (_M_cmpts.size() >= 2)
{ {
for (auto __it = _M_cmpts.begin(), __end = std::prev(_M_cmpts.end()); const auto parent = std::prev(_M_cmpts.end(), 2);
__it != __end; ++__it) const auto len = parent->_M_pos + parent->_M_pathname.length();
{ __ret.assign(_M_pathname.substr(0, len));
__ret /= *__it;
}
} }
return __ret; return __ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment