mirror of
https://github.com/python/cpython.git
synced 2025-07-31 23:23:11 +00:00
Bug #1560179: speed up posixpath.(dir|base)name
This commit is contained in:
parent
8134d06e08
commit
65ad043ea3
1 changed files with 9 additions and 4 deletions
|
@ -106,18 +106,23 @@ def splitdrive(p):
|
||||||
return '', 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):
|
def basename(p):
|
||||||
"""Returns the final component of a pathname"""
|
"""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):
|
def dirname(p):
|
||||||
"""Returns the directory component of a pathname"""
|
"""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?
|
# Is a path a symbolic link?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue