8000 gh-117686: Improve the performance of ntpath.expanduser() (#117690) · python/cpython@f90ff03 · GitHub
[go: up one dir, main page]

Skip to content

Commit f90ff03

Browse files
authored
gh-117686: Improve the performance of ntpath.expanduser() (#117690)
Refactor out _get_bothseps() call from the loop.
1 parent 0d42ac9 commit f90ff03

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

Lib/ntpath.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,13 +368,15 @@ def expanduser(path):
368368
If user or $HOME is unknown, do nothing."""
369369
path = os.fspath(path)
370370
if isinstance(path, bytes):
371+
seps = b'\\/'
371372
tilde = b'~'
372373
else:
374+
seps = '\\/'
373375
tilde = '~'
374376
if not path.startswith(tilde):
375377
return path
376378
i, n = 1, len(path)
377-
while i < n and path[i] not in _get_bothseps(path):
379+
while i < n and path[i] not in seps:
378380
i += 1
379381

380382
if 'USERPROFILE' in os.environ:

Misc/NEWS.d/3.13.0a6.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.. release date: 2024-04-09
55
.. section: Core and Builtins
66
7-
Improve performance of :func:`os.path.join`.
7+
Improve performance of :func:`os.path.join` and :func:`os.path.expanduser`.
88

99
..
1010

0 commit comments

Comments
 (0)
0