Mailing List Archive

gh-117648: Improve performance of os.join (#117654)
https://github.com/python/cpython/commit/99852d9e65aef11fed4bb7bd064e2218220f1ac9
commit: 99852d9e65aef11fed4bb7bd064e2218220f1ac9
branch: main
author: Nice Zombies <nineteendo19d0@gmail.com>
committer: erlend-aasland <erlend.aasland@protonmail.com>
date: 2024-04-09T10:27:14+02:00
summary:

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>

files:
A Misc/NEWS.d/next/Core and Builtins/2024-04-08-20-26-15.gh-issue-117648.NzVEa7.rst
M Lib/ntpath.py
M Lib/posixpath.py

diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index f9f6c78566e8ed..da5231ff2c0931 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -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
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index b7fbdff20cac99..79e65587e66282 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -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):
diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-04-08-20-26-15.gh-issue-117648.NzVEa7.rst b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-20-26-15.gh-issue-117648.NzVEa7.rst
new file mode 100644
index 00000000000000..c7e0dfcc461fc9
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-20-26-15.gh-issue-117648.NzVEa7.rst
@@ -0,0 +1 @@
+Speedup :func:`os.path.join` by up to 6% on Windows.

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-leave@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: list-python-checkins@lists.gossamer-threads.com