Mercurial > cpython-lru_cache-weakref
diff Lib/posixpath.py @ 40114:c4c4eec64c13 legacy-trunk
Bug #1560179: speed up posixpath.(dir|base)name
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Thu, 12 Oct 2006 13:08:16 +0000 |
| parents | b9a2ef1302d4 |
| children | 98bbc93bd55b |
line wrap: on
line diff
--- a/Lib/posixpath.py Thu Oct 12 12:33:07 2006 +0000 +++ b/Lib/posixpath.py Thu Oct 12 13:08:16 2006 +0000 @@ -106,18 +106,23 @@ 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?
