From f53562b0e7cb5fb2dcf987e76f57724d2e106d31 Mon Sep 17 00:00:00 2001 From: nineteendo Date: Mon, 8 Apr 2024 22:18:31 +0200 Subject: [PATCH 1/3] Improve performance of os.join by replacing map with a direct method call Co-authored-by: Pieter Eendebak --- Lib/ntpath.py | 2 +- Lib/posixpath.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) 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): From 896b576c2a2fea579450842bfe42b2de61af3ff8 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 8 Apr 2024 20:26:16 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2024-04-08-20-26-15.gh-issue-117648.NzVEa7.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-04-08-20-26-15.gh-issue-117648.NzVEa7.rst 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..cd951a512d56b9 --- /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 and up to ?% on Unix. From 51f5d0c14196cb729bfb655e382edd56186a9fd5 Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Tue, 9 Apr 2024 08:12:30 +0200 Subject: [PATCH 3/3] Update 2024-04-08-20-26-15.gh-issue-117648.NzVEa7.rst --- .../2024-04-08-20-26-15.gh-issue-117648.NzVEa7.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index cd951a512d56b9..c7e0dfcc461fc9 100644 --- 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 @@ -1 +1 @@ -Speedup :func:`os.path.join` by up to 6% on Windows and up to ?% on Unix. +Speedup :func:`os.path.join` by up to 6% on Windows.