util: implement a faster os.path.split for posix systems
authorBryan O'Sullivan <bryano@fb.com>
Fri, 14 Sep 2012 12:08:17 -0700
changeset 17560 9ee25d7b1aed
parent 17559 83785bb56062
child 17561 4647aa33ad81
util: implement a faster os.path.split for posix systems This is not yet used.
mercurial/posix.py
mercurial/util.py
mercurial/windows.py
--- 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
--- a/mercurial/util.py	Fri Sep 14 12:07:33 2012 -0700
+++ b/mercurial/util.py	Fri Sep 14 12:08:17 2012 -0700
@@ -62,6 +62,7 @@
 setsignalhandler = platform.setsignalhandler
 shellquote = platform.shellquote
 spawndetached = platform.spawndetached
+split = platform.split
 sshargs = platform.sshargs
 statfiles = platform.statfiles
 termwidth = platform.termwidth
--- a/mercurial/windows.py	Fri Sep 14 12:07:33 2012 -0700
+++ b/mercurial/windows.py	Fri Sep 14 12:08:17 2012 -0700
@@ -20,6 +20,7 @@
 samefile = win32.samefile
 setsignalhandler = win32.setsignalhandler
 spawndetached = win32.spawndetached
+split = os.path.split
 termwidth = win32.termwidth
 testpid = win32.testpid
 unlink = win32.unlink