From 9206877fc85b8d5092fabe849f87e8477661237c Mon Sep 17 00:00:00 2001 From: Steffen Schuemann Date: Thu, 21 Jan 2021 00:06:35 +0100 Subject: [PATCH 1/2] refs #88, work on path::parent_path() optimization --- include/ghc/filesystem.hpp | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 4469590..2a3724b 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -586,6 +586,7 @@ public: pointer operator->() const; private: + friend class path; impl_string_type::const_iterator increment(const std::string::const_iterator& pos) const; impl_string_type::const_iterator decrement(const std::string::const_iterator& pos) const; void updateCurrent(); @@ -2702,22 +2703,18 @@ GHC_INLINE path path::relative_path() const GHC_INLINE path path::parent_path() const { - if (has_relative_path()) { + auto rootPathLen = root_name_length() + (has_root_directory() ? 1 : 0); + if(rootPathLen < _path.length()) { if (empty() || begin() == --end()) { return path(); } else { - path pp; - for (string_type s : input_iterator_range(begin(), --end())) { - if (s == "/") { - // don't use append to join a path- - pp += s; - } - else { - pp /= s; - } + auto piter = end(); + auto iter = piter.decrement(_path.end()); + if(iter > _path.begin() + rootPathLen && *iter != '/') { + --iter; } - return pp; + return path(_path.begin(), iter, format::generic_format); } } else { @@ -3008,8 +3005,8 @@ GHC_INLINE path::impl_string_type::const_iterator path::iterator::decrement(cons GHC_INLINE void path::iterator::updateCurrent() { - if (_iter != _first && _iter != _last && (*_iter == '/' && _iter != _root) && (_iter + 1 == _last)) { - _current = ""; + if ((_iter == _last) || (_iter != _first && _iter != _last && (*_iter == '/' && _iter != _root) && (_iter + 1 == _last))) { + _current.clear(); } else { _current.assign(_iter, increment(_iter)); From 6bf13c0ce138e9e0cf902519c21f0a61e593e73e Mon Sep 17 00:00:00 2001 From: Steffen Schuemann Date: Thu, 21 Jan 2021 00:23:15 +0100 Subject: [PATCH 2/2] refs #88, fix signed/unsigned issue --- include/ghc/filesystem.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 2a3724b..3ac0129 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -2711,7 +2711,7 @@ GHC_INLINE path path::parent_path() const else { auto piter = end(); auto iter = piter.decrement(_path.end()); - if(iter > _path.begin() + rootPathLen && *iter != '/') { + if(iter > _path.begin() + static_cast(rootPathLen) && *iter != '/') { --iter; } return path(_path.begin(), iter, format::generic_format);