Skip to content

Commit 99852d9

Browse files
gh-117648: Improve performance of os.join (#117654)
Replace map() with a method call in the loop body. Co-authored-by: Pieter Eendebak <[email protected]>
1 parent 19a2202 commit 99852d9

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

Lib/ntpath.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def join(path, *paths):
111111
if not paths:
112112
path[:0] + sep #23780: Ensure compatible data type even if p is null.
113113
result_drive, result_root, result_path = splitroot(path)
114-
for p in map(os.fspath, paths):
114+
for p in paths:
115115
p_drive, p_root, p_path = splitroot(p)
116116
if p_root:
117117
# Second path is absolute

Lib/posixpath.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ def join(a, *p):
7979
try:
8080
if not p:
8181
path[:0] + sep #23780: Ensure compatible data type even if p is null.
82-
for b in map(os.fspath, p):
82+
for b in p:
83+
b = os.fspath(b)
8384
if b.startswith(sep):
8485
path = b
8586
elif not path or path.endswith(sep):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Speedup :func:`os.path.join` by up to 6% on Windows.

0 commit comments

Comments
 (0)