From: Nice Zombies Date: Thu, 18 Apr 2024 07:26:34 +0000 (+0200) Subject: gh-117641: Improve the perfornance of posixpath.commonpath() (#117652) X-Git-Tag: v3.13.0b1~363 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b848b944bb4730ab4dcaeb15b0b1713c3f68ec7d;p=thirdparty%2FPython%2Fcpython.git gh-117641: Improve the perfornance of posixpath.commonpath() (#117652) --- diff --git a/Lib/posixpath.py b/Lib/posixpath.py index 79cda50753e0..f1960ddb88e5 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 000000000000..e313c133b721 --- /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.