aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2019-05-29 23:00:45 +0100
committerJonathan Wakely <redi@gcc.gnu.org>2019-05-29 23:00:45 +0100
commite5ccb10ad04e5cc1c44ea4d50a501840927ad70e (patch)
treed0b2dd96111966903022c5a8936a2ab2a4297fcf
parente800d6dc2cb329a1b64bb3af136164910778a40c (diff)
downloadgcc-e5ccb10ad04e5cc1c44ea4d50a501840927ad70e.zip
gcc-e5ccb10ad04e5cc1c44ea4d50a501840927ad70e.tar.gz
gcc-e5ccb10ad04e5cc1c44ea4d50a501840927ad70e.tar.bz2
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
-rw-r--r--libstdc++-v3/ChangeLog3
-rw-r--r--libstdc++-v3/src/c++17/fs_path.cc8
2 files changed, 6 insertions, 5 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index b209460..b6b7a05 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,8 @@
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.
PR libstdc++/85494 use rdseed and rand_s in std::random_device
diff --git a/libstdc++-v3/src/c++17/fs_path.cc b/libstdc++-v3/src/c++17/fs_path.cc
index 8e01bf5..c438ddc 100644
--- a/libstdc++-v3/src/c++17/fs_path.cc
+++ b/libstdc++-v3/src/c++17/fs_path.cc
@@ -1523,11 +1523,9 @@ path::parent_path() const
__ret = *this;
else if (_M_cmpts.size() >= 2)
{
- for (auto __it = _M_cmpts.begin(), __end = std::prev(_M_cmpts.end());
- __it != __end; ++__it)
- {
- __ret /= *__it;
- }
+ const auto parent = std::prev(_M_cmpts.end(), 2);
+ const auto len = parent->_M_pos + parent->_M_pathname.length();
+ __ret.assign(_M_pathname.substr(0, len));
}
return __ret;
}