Patch #536661: Improve performance of splitext. Add test_macpath.

This commit is contained in:
Martin v. Löwis 2002-12-12 20:30:20 +00:00
parent 427a290c9a
commit de3337913f
6 changed files with 95 additions and 42 deletions

View file

@ -78,20 +78,11 @@ def split(p):
def splitext(p):
"""Split the extension from a pathname. Extension is everything from the
last dot to the end. Returns "(root, ext)", either part may be empty."""
root, ext = '', ''
for c in p:
if c == '/':
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<=p.rfind('/'):
return p, ''
else:
return p[:i], p[i:]
# Split a pathname into a drive specification and the rest of the