diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2002-12-12 20:30:20 +0000 |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2002-12-12 20:30:20 +0000 |
commit | de3337913f08266b16842f21a67427d10725ed8f (patch) | |
tree | f54488a637762efbde037aac60ebbfb83a217735 /Lib/ntpath.py | |
parent | 427a290c9afca605ab8ed799f0072d890318b837 (diff) | |
download | cpython-git-de3337913f08266b16842f21a67427d10725ed8f.tar.gz |
Patch #536661: Improve performance of splitext. Add test_macpath.
Diffstat (limited to 'Lib/ntpath.py')
-rw-r--r-- | Lib/ntpath.py | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/Lib/ntpath.py b/Lib/ntpath.py index 0f1dd4dc60..4e7bb885a9 100644 --- a/Lib/ntpath.py +++ b/Lib/ntpath.py @@ -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. |