summaryrefslogtreecommitdiffstats
path: root/Lib/macpath.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2002-12-12 20:30:20 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2002-12-12 20:30:20 (GMT)
commitde3337913f08266b16842f21a67427d10725ed8f (patch)
treef54488a637762efbde037aac60ebbfb83a217735 /Lib/macpath.py
parent427a290c9afca605ab8ed799f0072d890318b837 (diff)
downloadcpython-de3337913f08266b16842f21a67427d10725ed8f.zip
cpython-de3337913f08266b16842f21a67427d10725ed8f.tar.gz
cpython-de3337913f08266b16842f21a67427d10725ed8f.tar.bz2
Patch #536661: Improve performance of splitext. Add test_macpath.
Diffstat (limited to 'Lib/macpath.py')
-rw-r--r--Lib/macpath.py19
1 files changed, 5 insertions, 14 deletions
diff --git a/Lib/macpath.py b/Lib/macpath.py
index f19b4f7..734bae2 100644
--- a/Lib/macpath.py
+++ b/Lib/macpath.py
@@ -62,20 +62,11 @@ def splitext(p):
pathname component; the root is everything before that.
It is always true that root + ext == p."""
- 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:]
def splitdrive(p):