]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117648: Improve performance of os.join (#117654)
authorNice Zombies <nineteendo19d0@gmail.com>
Tue, 9 Apr 2024 08:27:14 +0000 (10:27 +0200)
committerGitHub <noreply@github.com>
Tue, 9 Apr 2024 08:27:14 +0000 (10:27 +0200)
Replace map() with a method call in the loop body.

Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Lib/ntpath.py
Lib/posixpath.py
Misc/NEWS.d/next/Core and Builtins/2024-04-08-20-26-15.gh-issue-117648.NzVEa7.rst [new file with mode: 0644]

index f9f6c78566e8edd0e906704fb5eddec15df49c31..da5231ff2c0931d0bd67fd205ed7e316cac0e7ce 100644 (file)
@@ -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
index b7fbdff20cac99cc476782a135497269cd17f6a8..79e65587e66282a8cbf9b6d1f046587e485083e6 100644 (file)
@@ -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):
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 (file)
index 0000000..c7e0dfc
--- /dev/null
@@ -0,0 +1 @@
+Speedup :func:`os.path.join` by up to 6% on Windows.