Skip to content

Commit

Permalink
gh-117648: Improve performance of os.join (#117654)
Browse files Browse the repository at this point in the history
Replace map() with a method call in the loop body.

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
  • Loading branch information
nineteendo and eendebakpt committed Apr 9, 2024
1 parent 19a2202 commit 99852d9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Lib/ntpath.py
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Lib/posixpath.py
Expand Up @@ -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):
Expand Down
@@ -0,0 +1 @@
Speedup :func:`os.path.join` by up to 6% on Windows.

0 comments on commit 99852d9

Please sign in to comment.