From 792b2a2d252dcfec950c96c70e88439a7622d774 Mon Sep 17 00:00:00 2001 From: nineteendo Date: Mon, 8 Apr 2024 16:28:37 +0200 Subject: [PATCH 1/7] Remove redundant type check in `os.path.join()` --- Lib/ntpath.py | 2 -- Lib/posixpath.py | 6 ++---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/Lib/ntpath.py b/Lib/ntpath.py index f9f6c78566e8ed..43763bd4aed082 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -108,8 +108,6 @@ def join(path, *paths): seps = '\\/' colon_seps = ':\\/' try: - 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): p_drive, p_root, p_path = splitroot(p) diff --git a/Lib/posixpath.py b/Lib/posixpath.py index b7fbdff20cac99..2e13a697eb42a1 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -77,12 +77,10 @@ def join(a, *p): sep = _get_sep(a) path = a try: - if not p: - path[:0] + sep #23780: Ensure compatible data type even if p is null. for b in map(os.fspath, p): - if b.startswith(sep): + if b.startswith(sep) or not path: path = b - elif not path or path.endswith(sep): + elif path.endswith(sep): path += b else: path += sep + b From f131a37eb1d8147bc1d66ddef1d34ea57266a538 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Mon, 8 Apr 2024 14:33:39 +0000 Subject: [PATCH 2/7] =?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-14-33-38.gh-issue-117636.exnRKd.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst new file mode 100644 index 00000000000000..dcd7ebc6512c77 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst @@ -0,0 +1 @@ +Speedup :func:`os.path.join()` by up to 1.1 times on Windows, up to 1.? times on Unix. From fc86da788a3ccc15bd89e8bcd4eacd9cac3b20a0 Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Mon, 8 Apr 2024 16:35:05 +0200 Subject: [PATCH 3/7] Update 2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst --- .../2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst index dcd7ebc6512c77..20443d95c5d6e8 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst @@ -1 +1 @@ -Speedup :func:`os.path.join()` by up to 1.1 times on Windows, up to 1.? times on Unix. +Speedup :func:`os.path.join()` by up to 7% on Windows and ?% times on Unix. From 45bf36803870c7f4433e93fa94b2bff230500ea1 Mon Sep 17 00:00:00 2001 From: nineteendo Date: Mon, 8 Apr 2024 16:42:49 +0200 Subject: [PATCH 4/7] Add test --- Lib/test/test_posixpath.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Lib/test/test_posixpath.py b/Lib/test/test_posixpath.py index ff78410738022d..645fcebc26a151 100644 --- a/Lib/test/test_posixpath.py +++ b/Lib/test/test_posixpath.py @@ -56,6 +56,8 @@ def test_join(self): self.assertEqual(fn(b"/foo", b"bar", b"baz"), b"/foo/bar/baz") self.assertEqual(fn(b"/foo/", b"bar/", b"baz/"), b"/foo/bar/baz/") + self.assertEqual(fn("a", ""), "a/") + self.assertEqual(fn("a", "", ""), "a/") self.assertEqual(fn("a", "b"), "a/b") self.assertEqual(fn("a", "b/"), "a/b/") self.assertEqual(fn("a/", "b"), "a/b") From 6175cb835dd6b8b32ca7aa8b3eafc6fca778300f Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Tue, 9 Apr 2024 08:45:05 +0200 Subject: [PATCH 5/7] Update 2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst --- .../2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst index 20443d95c5d6e8..0f31ea30eb55db 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst @@ -1 +1 @@ -Speedup :func:`os.path.join()` by up to 7% on Windows and ?% times on Unix. +Speedup :func:`os.path.join()` by up to 7% on Windows and 24% times on Unix for few components. From 92ef4a8c38ad5cd0ff1975df2938663b0085b0cf Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Tue, 9 Apr 2024 22:02:58 +0200 Subject: [PATCH 6/7] Update 2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst --- .../2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst index 0f31ea30eb55db..92033ddd95d973 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst @@ -1 +1 @@ -Speedup :func:`os.path.join()` by up to 7% on Windows and 24% times on Unix for few components. +Speedup :func:`os.path.join()`. From 0c6fc29efbd46dbb5ffbac257000861c70c02a88 Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Thu, 11 Apr 2024 11:36:28 +0200 Subject: [PATCH 7/7] Update 2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst --- .../2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst index 92033ddd95d973..7d7cb506352193 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-14-33-38.gh-issue-117636.exnRKd.rst @@ -1 +1 @@ -Speedup :func:`os.path.join()`. +Speedup :func:`os.path.join`.