diff mercurial/posix.py @ 17560:9ee25d7b1aed

util: implement a faster os.path.split for posix systems This is not yet used.
author Bryan O'Sullivan <bryano@fb.com>
date Fri, 14 Sep 2012 12:08:17 -0700
parents fc24c10424d2
children 74912fe3d718
line wrap: on
line diff
--- a/mercurial/posix.py	Fri Sep 14 12:07:33 2012 -0700
+++ b/mercurial/posix.py	Fri Sep 14 12:08:17 2012 -0700
@@ -20,6 +20,16 @@
 umask = os.umask(0)
 os.umask(umask)
 
+def split(p):
+    '''Same as os.path.split, but faster'''
+    ht = p.rsplit('/', 1)
+    if len(ht) == 1:
+        return '', p
+    nh = ht[0].rstrip('/')
+    if nh:
+        return nh, ht[1]
+    return ht
+
 def openhardlinks():
     '''return true if it is safe to hold open file handles to hardlinks'''
     return True