mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00
GH-113528: Deoptimise pathlib._abc.PurePathBase.parts
(#113883)
Implement `parts` using `_stack`, which itself calls `pathmod.split()` repeatedly. This avoids use of `_tail`, which will be moved to `PurePath` shortly.
This commit is contained in:
parent
623b338adf
commit
5c7bd0e398
2 changed files with 13 additions and 4 deletions
|
@ -195,6 +195,15 @@ class PurePath(_abc.PurePathBase):
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
return self._parts_normcase >= other._parts_normcase
|
return self._parts_normcase >= other._parts_normcase
|
||||||
|
|
||||||
|
@property
|
||||||
|
def parts(self):
|
||||||
|
"""An object providing sequence-like access to the
|
||||||
|
components in the filesystem path."""
|
||||||
|
if self.drive or self.root:
|
||||||
|
return (self.drive + self.root,) + tuple(self._tail)
|
||||||
|
else:
|
||||||
|
return tuple(self._tail)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def parent(self):
|
def parent(self):
|
||||||
"""The logical parent of the path."""
|
"""The logical parent of the path."""
|
||||||
|
|
|
@ -381,10 +381,10 @@ class PurePathBase:
|
||||||
def parts(self):
|
def parts(self):
|
||||||
"""An object providing sequence-like access to the
|
"""An object providing sequence-like access to the
|
||||||
components in the filesystem path."""
|
components in the filesystem path."""
|
||||||
if self.drive or self.root:
|
anchor, parts = self._stack
|
||||||
return (self.drive + self.root,) + tuple(self._tail)
|
if anchor:
|
||||||
else:
|
parts.append(anchor)
|
||||||
return tuple(self._tail)
|
return tuple(reversed(parts))
|
||||||
|
|
||||||
def joinpath(self, *pathsegments):
|
def joinpath(self, *pathsegments):
|
||||||
"""Combine this path with one or several arguments, and return a
|
"""Combine this path with one or several arguments, and return a
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue