gh-117648: Improve performance of os.join (#117654)

Replace map() with a method call in the loop body.

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
This commit is contained in:
Nice Zombies 2024-04-09 10:27:14 +02:00 committed by GitHub
parent 19a2202067
commit 99852d9e65
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 4 additions and 2 deletions

View file

@ -111,7 +111,7 @@ def join(path, *paths):
if not paths:
path[:0] + sep #23780: Ensure compatible data type even if p is null.
result_drive, result_root, result_path = splitroot(path)
for p in map(os.fspath, paths):
for p in paths:
p_drive, p_root, p_path = splitroot(p)
if p_root:
# Second path is absolute

View file

@ -79,7 +79,8 @@ def join(a, *p):
try:
if not p:
path[:0] + sep #23780: Ensure compatible data type even if p is null.
for b in map(os.fspath, p):
for b in p:
b = os.fspath(b)
if b.startswith(sep):
path = b
elif not path or path.endswith(sep):

View file

@ -0,0 +1 @@
Speedup :func:`os.path.join` by up to 6% on Windows.