Skip to content

Commit

Permalink
Bug #1560179: speed up posixpath.(dir|base)name
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.python.org/projects/python/trunk@52316 6015fed2-1504-0410-9fe1-9d1591cc4771
  • Loading branch information
georg.brandl committed Oct 12, 2006
1 parent 5590fa9 commit 49c0c6e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Lib/posixpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit 49c0c6e

Please sign in to comment.