summaryrefslogtreecommitdiffstats
path: root/Lib/posixpath.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-10-12 13:08:16 (GMT)
committerGeorg Brandl <georg@python.org>2006-10-12 13:08:16 (GMT)
commit65ad043ea3c331ee41b19746f3a15b19bef2dab1 (patch)
treef930e91527bfc26edd8f272f883ddd616dccef13 /Lib/posixpath.py
parent8134d06e08a009c3bae040317dab6dd541241c7e (diff)
downloadcpython-65ad043ea3c331ee41b19746f3a15b19bef2dab1.zip
cpython-65ad043ea3c331ee41b19746f3a15b19bef2dab1.tar.gz
cpython-65ad043ea3c331ee41b19746f3a15b19bef2dab1.tar.bz2
Bug #1560179: speed up posixpath.(dir|base)name
Diffstat (limited to 'Lib/posixpath.py')
-rw-r--r--Lib/posixpath.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index 07ab4b6..1521236 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -106,18 +106,23 @@ def splitdrive(p):
return '', p
-# Return the tail (basename) part of a path.
+# Return the tail (basename) part of a path, same as split(path)[1].
def basename(p):
"""Returns the final component of a pathname"""
- return split(p)[1]
+ i = p.rfind('/') + 1
+ return p[i:]
-# Return the head (dirname) part of a path.
+# Return the head (dirname) part of a path, same as split(path)[0].
def dirname(p):
"""Returns the directory component of a pathname"""
- return split(p)[0]
+ i = p.rfind('/') + 1
+ head = p[:i]
+ if head and head != '/'*len(head):
+ head = head.rstrip('/')
+ return head
# Is a path a symbolic link?