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()` (python#113532)

Call straight through to `joinpath()` in `PathBase._make_child_relpath()`.
Move optimised/caching code to `pathlib.Path._make_child_relpath()`
  • Loading branch information
barneygale authored and Glyphack committed Jan 27, 2024
1 parent 33b5824 commit 5e7b47e
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 @@ -405,6 +405,22 @@ def _make_child_entry(self, entry):
path._tail_cached = self._tail + [entry.name]
return path

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 glob(self, pattern, *, case_sensitive=None, follow_symlinks=None):
"""Iterate over this subtree and yield all existing files (of any
kind, including directories) matching the given relative pattern.
Expand Down
15 changes: 1 addition & 14 deletions Lib/pathlib/_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,20 +753,7 @@ def _make_child_entry(self, entry):
return entry

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 5e7b47e

Please sign in to comment.