mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Patch #536661: Improve performance of splitext. Add test_macpath.
This commit is contained in:
parent
427a290c9a
commit
de3337913f
6 changed files with 95 additions and 42 deletions
|
@ -169,20 +169,12 @@ def splitext(p):
|
|||
|
||||
Extension is everything from the last dot to the end.
|
||||
Return (root, ext), either part may be empty."""
|
||||
root, ext = '', ''
|
||||
for c in p:
|
||||
if c in ['/','\\']:
|
||||
root, ext = root + ext + c, ''
|
||||
elif c == '.':
|
||||
if ext:
|
||||
root, ext = root + ext, c
|
||||
else:
|
||||
ext = c
|
||||
elif ext:
|
||||
ext = ext + c
|
||||
else:
|
||||
root = root + c
|
||||
return root, ext
|
||||
|
||||
i = p.rfind('.')
|
||||
if i<=max(p.rfind('/'), p.rfind('\\')):
|
||||
return p, ''
|
||||
else:
|
||||
return p[:i], p[i:]
|
||||
|
||||
|
||||
# Return the tail (basename) part of a path.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue