Skip to content

Commit

Permalink
pythonGH-113528: Deoptimise `pathlib._abc.PathBase._make_child_relpat…
Browse files Browse the repository at this point in the history
…h()`

Call straight through to `joinpath()` in `PathBase._make_child_relpath()`.
Move optimised/caching code to `pathlib.Path._make_child_relpath()`
  • Loading branch information
barneygale committed Dec 28, 2023
1 parent 1b19d73 commit ec72e03
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
16 changes: 16 additions & 0 deletions Lib/pathlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,22 @@ def iterdir(self):
def _scandir(self):
return os.scandir(self)

def _make_child_relpath(self, name):
path_str = str(self)
tail = self._tail
if tail:
path_str = f'{path_str}{self.pathmod.sep}{name}'
elif path_str != '.':
path_str = f'{path_str}{name}'
else:
path_str = name
path = self.with_segments(path_str)
path._str = path_str
path._drv = self.drive
path._root = self.root
path._tail_cached = tail + [name]
return path

def absolute(self):
"""Return an absolute version of this path
No normalization or symlink resolution is performed.
Expand Down
15 changes: 1 addition & 14 deletions Lib/pathlib/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,20 +789,7 @@ def _scandir(self):
return nullcontext(self.iterdir())

def _make_child_relpath(self, name):
path_str = str(self)
tail = self._tail
if tail:
path_str = f'{path_str}{self.pathmod.sep}{name}'
elif path_str != '.':
path_str = f'{path_str}{name}'
else:
path_str = name
path = self.with_segments(path_str)
path._str = path_str
path._drv = self.drive
path._root = self.root
path._tail_cached = tail + [name]
return path
return self.joinpath(name)

def glob(self, pattern, *, case_sensitive=None, follow_symlinks=None):
"""Iterate over this subtree and yield all existing files (of any
Expand Down

0 comments on commit ec72e03

Please sign in to comment.