diff options
author | Nice Zombies <nineteendo19d0@gmail.com> | 2024-04-10 08:28:48 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-10 08:28:48 (GMT) |
commit | f90ff0367271ea474b4ce3c8e2643cb51d188c18 (patch) | |
tree | 171cd734705c44fd983c71ea3987fd896f533834 /Lib/ntpath.py | |
parent | 0d42ac9474f857633d00b414c0715f4efa73f1ca (diff) | |
download | cpython-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.py | 4 |
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: |