summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2024-01-09 19:11:17 (GMT)
committerGitHub <noreply@github.com>2024-01-09 19:11:17 (GMT)
commit9100fc407e8c7038e7214b600b4ae568ae5510e3 (patch)
tree23428a62d0c6fdaf5b8d8bf6e2efa3a1e16a20b8
parent2fd2e747930987eb8ed4929cf0132e85db759dab (diff)
downloadcpython-9100fc407e8c7038e7214b600b4ae568ae5510e3.zip
cpython-9100fc407e8c7038e7214b600b4ae568ae5510e3.tar.gz
cpython-9100fc407e8c7038e7214b600b4ae568ae5510e3.tar.bz2
GH-113528: Deoptimise `pathlib._abc.PathBase._make_child_relpath()` (#113532)
Call straight through to `joinpath()` in `PathBase._make_child_relpath()`. Move optimised/caching code to `pathlib.Path._make_child_relpath()`
-rw-r--r--Lib/pathlib/__init__.py16
-rw-r--r--Lib/pathlib/_abc.py15
2 files changed, 17 insertions, 14 deletions
diff --git a/Lib/pathlib/__init__.py b/Lib/pathlib/__init__.py
index a432d45..749c68d 100644
--- a/Lib/pathlib/__init__.py
+++ b/Lib/pathlib/__init__.py
@@ -405,6 +405,22 @@ class Path(_abc.PathBase, PurePath):
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.
diff --git a/Lib/pathlib/_abc.py b/Lib/pathlib/_abc.py
index be22ece..0e442ae 100644
--- a/Lib/pathlib/_abc.py
+++ b/Lib/pathlib/_abc.py
@@ -753,20 +753,7 @@ class PathBase(PurePathBase):
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