From: Nice Zombies Date: Tue, 9 Apr 2024 08:27:14 +0000 (+0200) Subject: gh-117648: Improve performance of os.join (#117654) X-Git-Tag: v3.13.0a6~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=99852d9e65aef11fed4bb7bd064e2218220f1ac9;p=thirdparty%2FPython%2Fcpython.git gh-117648: Improve performance of os.join (#117654) Replace map() with a method call in the loop body. Co-authored-by: Pieter Eendebak --- diff --git a/Lib/ntpath.py b/Lib/ntpath.py index f9f6c78566e8..da5231ff2c09 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 b7fbdff20cac..79e65587e662 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 000000000000..c7e0dfcc461f --- /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.