]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-117686: Improve the performance of ntpath.expanduser() (#117690)
authorNice Zombies <nineteendo19d0@gmail.com>
Wed, 10 Apr 2024 08:28:48 +0000 (10:28 +0200)
committerGitHub <noreply@github.com>
Wed, 10 Apr 2024 08:28:48 +0000 (10:28 +0200)
Refactor out _get_bothseps() call from the loop.

Lib/ntpath.py
Misc/NEWS.d/3.13.0a6.rst

index da5231ff2c0931d0bd67fd205ed7e316cac0e7ce..f5d1a2195dd633d21c7a509fc313b91a3721eb9a 100644 (file)
@@ -368,13 +368,15 @@ def expanduser(path):
     If user or $HOME is unknown, do nothing."""
     path = os.fspath(path)
     if isinstance(path, bytes):
+        seps = b'\\/'
         tilde = b'~'
     else:
+        seps = '\\/'
         tilde = '~'
     if not path.startswith(tilde):
         return path
     i, n = 1, len(path)
-    while i < n and path[i] not in _get_bothseps(path):
+    while i < n and path[i] not in seps:
         i += 1
 
     if 'USERPROFILE' in os.environ:
index 52735dba3578b5473404be099054add5211e5758..06807b396ed5da035aba9cd1c6402a00ef165b1f 100644 (file)
@@ -4,7 +4,7 @@
 .. release date: 2024-04-09
 .. section: Core and Builtins
 
-Improve performance of :func:`os.path.join`.
+Improve performance of :func:`os.path.join` and :func:`os.path.expanduser`.
 
 ..