summaryrefslogtreecommitdiffstats
path: root/Lib/ntpath.py
diff options
context:
space:
mode:
authorNice Zombies <nineteendo19d0@gmail.com>2024-04-10 08:28:48 (GMT)
committerGitHub <noreply@github.com>2024-04-10 08:28:48 (GMT)
commitf90ff0367271ea474b4ce3c8e2643cb51d188c18 (patch)
tree171cd734705c44fd983c71ea3987fd896f533834 /Lib/ntpath.py
parent0d42ac9474f857633d00b414c0715f4efa73f1ca (diff)
downloadcpython-f90ff0367271ea474b4ce3c8e2643cb51d188c18.zip
cpython-f90ff0367271ea474b4ce3c8e2643cb51d188c18.tar.gz
cpython-f90ff0367271ea474b4ce3c8e2643cb51d188c18.tar.bz2
gh-117686: Improve the performance of ntpath.expanduser() (#117690)
Refactor out _get_bothseps() call from the loop.
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r--Lib/ntpath.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py
index da5231f..f5d1a21 100644
--- a/Lib/ntpath.py
+++ b/Lib/ntpath.py
@@ -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: