summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNice Zombies <nineteendo19d0@gmail.com>2024-04-09 08:27:14 (GMT)
committerGitHub <noreply@github.com>2024-04-09 08:27:14 (GMT)
commit99852d9e65aef11fed4bb7bd064e2218220f1ac9 (patch)
treea38d466c53bd8d9904462f11d2bc1c3ec2405325
parent19a22020676a599e1c92a24f841196645ddd9895 (diff)
downloadcpython-99852d9e65aef11fed4bb7bd064e2218220f1ac9.zip
cpython-99852d9e65aef11fed4bb7bd064e2218220f1ac9.tar.gz
cpython-99852d9e65aef11fed4bb7bd064e2218220f1ac9.tar.bz2
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>
-rw-r--r--Lib/ntpath.py2
-rw-r--r--Lib/posixpath.py3
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2024-04-08-20-26-15.gh-issue-117648.NzVEa7.rst1
3 files changed, 4 insertions, 2 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index f9f6c78..da5231f 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 b7fbdff..79e6558 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 0000000..c7e0dfc
--- /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.