https://github.com/python/cpython/commit/b848b944bb4730ab4dcaeb15b0b1713c3f68ec7d
commit: b848b944bb4730ab4dcaeb15b0b1713c3f68ec7d
branch: main
author: Nice Zombies <[email protected]>
committer: erlend-aasland <[email protected]>
date: 2024-04-18T09:26:34+02:00
summary:

gh-117641: Improve the perfornance of posixpath.commonpath() (#117652)

files:
A Misc/NEWS.d/next/Core and 
Builtins/2024-04-08-19-30-38.gh-issue-117641.oaBGSJ.rst
M Lib/posixpath.py

diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index 79cda50753e0d2..f1960ddb88e590 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 00000000000000..e313c133b72173
--- /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.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to