mirror of
https://git.mirrors.martin98.com/https://github.com/gulrak/filesystem
synced 2025-06-04 11:13:58 +08:00
refs #88, work on path::parent_path() optimization
This commit is contained in:
parent
8166dd1546
commit
9206877fc8
@ -586,6 +586,7 @@ public:
|
|||||||
pointer operator->() const;
|
pointer operator->() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend class path;
|
||||||
impl_string_type::const_iterator increment(const std::string::const_iterator& pos) const;
|
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;
|
impl_string_type::const_iterator decrement(const std::string::const_iterator& pos) const;
|
||||||
void updateCurrent();
|
void updateCurrent();
|
||||||
@ -2702,22 +2703,18 @@ GHC_INLINE path path::relative_path() const
|
|||||||
|
|
||||||
GHC_INLINE path path::parent_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()) {
|
if (empty() || begin() == --end()) {
|
||||||
return path();
|
return path();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
path pp;
|
auto piter = end();
|
||||||
for (string_type s : input_iterator_range<iterator>(begin(), --end())) {
|
auto iter = piter.decrement(_path.end());
|
||||||
if (s == "/") {
|
if(iter > _path.begin() + rootPathLen && *iter != '/') {
|
||||||
// don't use append to join a path-
|
--iter;
|
||||||
pp += s;
|
|
||||||
}
|
}
|
||||||
else {
|
return path(_path.begin(), iter, format::generic_format);
|
||||||
pp /= s;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pp;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -3008,8 +3005,8 @@ GHC_INLINE path::impl_string_type::const_iterator path::iterator::decrement(cons
|
|||||||
|
|
||||||
GHC_INLINE void path::iterator::updateCurrent()
|
GHC_INLINE void path::iterator::updateCurrent()
|
||||||
{
|
{
|
||||||
if (_iter != _first && _iter != _last && (*_iter == '/' && _iter != _root) && (_iter + 1 == _last)) {
|
if ((_iter == _last) || (_iter != _first && _iter != _last && (*_iter == '/' && _iter != _root) && (_iter + 1 == _last))) {
|
||||||
_current = "";
|
_current.clear();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_current.assign(_iter, increment(_iter));
|
_current.assign(_iter, increment(_iter));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user