mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
GH-101362: Call join() only when >1 argument supplied to pathlib.PurePath() (#101665)
GH-101362: Call join() only when >1 argument supplied to pathlib.PurePath
This reduces the time taken to run `PurePath("foo")` by ~15%
This commit is contained in:
parent
96e1022929
commit
3572c861d8
2 changed files with 6 additions and 1 deletions
|
|
@ -275,9 +275,12 @@ class PurePath(object):
|
|||
def _parse_parts(cls, parts):
|
||||
if not parts:
|
||||
return '', '', []
|
||||
elif len(parts) == 1:
|
||||
path = os.fspath(parts[0])
|
||||
else:
|
||||
path = cls._flavour.join(*parts)
|
||||
sep = cls._flavour.sep
|
||||
altsep = cls._flavour.altsep
|
||||
path = cls._flavour.join(*parts)
|
||||
if altsep:
|
||||
path = path.replace(altsep, sep)
|
||||
drv, root, rel = cls._flavour.splitroot(path)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
Speed up :class:`pathlib.PurePath` construction by calling
|
||||
:func:`os.path.join` only when two or more arguments are given.
|
||||
Loading…
Add table
Add a link
Reference in a new issue