From b848b944bb4730ab4dcaeb15b0b1713c3f68ec7d Mon Sep 17 00:00:00 2001 From: Nice Zombies Date: Thu, 18 Apr 2024 09:26:34 +0200 Subject: gh-117641: Improve the perfornance of posixpath.commonpath() (#117652) --- Lib/posixpath.py | 2 +- .../Core and Builtins/2024-04-08-19-30-38.gh-issue-117641.oaBGSJ.rst | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-04-08-19-30-38.gh-issue-117641.oaBGSJ.rst diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 79cda50..f1960dd 100644 --- a/Lib/posixpath.py +++ b/Lib/posixpath.py @@ -550,7 +550,7 @@ def commonpath(paths): split_paths = [path.split(sep) for path in paths] try: - isabs, = set(p[:1] == sep for p in paths) + isabs, = {p.startswith(sep) for p in paths} except ValueError: raise ValueError("Can't mix absolute and relative paths") from None diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-04-08-19-30-38.gh-issue-117641.oaBGSJ.rst b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-19-30-38.gh-issue-117641.oaBGSJ.rst new file mode 100644 index 0000000..e313c13 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-04-08-19-30-38.gh-issue-117641.oaBGSJ.rst @@ -0,0 +1 @@ +Speedup :func:`os.path.commonpath` on Unix. -- cgit v0.12