Bugs item #1560161, was opened at 2006-09-17 14:09
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1560161&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Michael Gebetsroither (einsteinmg)
Assigned to: Nobody/Anonymous (nobody)
Summary: Better/faster implementation of os.path.split
Initial Comment:
hi,
os.path.split is quite bad regarding performance on
long pathnames:
def split(p):
i = p.rfind('/') + 1
head, tail = p[:i], p[i:]
if head and head != '/'*len(head):
head = head.rstrip('/')
return head, tail
especially this: '/'*len(head)
this constructs an unnecessary string sometimes
thousands of chars long.
better would be:
if head and len(head) != head.count('/')
BUT:
what is this 'if head and head != '/'*len(head):' for?
this if is imho useless, because
if head exists and is not all '/' => rstrip '/'
imho better would be:
rstrip '/' from head and if head is empty add a '/'
would be the same effect, because a singel '/' is just
the same as a path as '/'*len(head).
def split(p):
i = p.rfind('/') + 1
head, tail = p[:i], p[i:]
head = head.rstrip('/')
if not head:
head = '/'
return head, tail
such a implementation would be ways faster for long
pathnames.
greets,
michael
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1560161&group_id=5470
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com