Skip to content

Commit

Permalink
refs #88, work on path::parent_path() optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
gulrak committed Jan 20, 2021
1 parent 8166dd1 commit 9206877
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions include/ghc/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ class GHC_FS_API_CLASS path::iterator
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();
Expand Down Expand Up @@ -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<iterator>(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 {
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 9206877

Please sign in to comment.