store: use fast C implementation of encodedir() if it's available
authorAdrian Buehlmann <adrian@cadifra.com>
Tue, 18 Sep 2012 11:44:16 +0200
changeset 17607 cc58dc47cb5e
parent 17606 318fb32b980e
child 17608 776240123525
store: use fast C implementation of encodedir() if it's available For a netbeans clone on Windows 7 x64: Encoding all paths in the fncache: Before: $ hg perffncacheencode ! wall 3.639000 comb 3.634823 user 3.634823 sys 0.000000 (best of 3) After: $ hg perffncacheencode ! wall 3.470000 comb 3.463222 user 3.463222 sys 0.000000 (best of 3) Writing fncache: Before: $ hg perffncachewrite ! wall 0.103000 comb 0.093601 user 0.093601 sys 0.000000 (best of 95) After: $ hg perffncachewrite ! wall 0.081000 comb 0.078001 user 0.062400 sys 0.015600 (best of 100)
mercurial/store.py
--- a/mercurial/store.py	Tue Sep 18 11:43:30 2012 +0200
+++ b/mercurial/store.py	Tue Sep 18 11:44:16 2012 +0200
@@ -6,22 +6,22 @@
 # GNU General Public License version 2 or any later version.
 
 from i18n import _
-import osutil, scmutil, util
+import osutil, scmutil, util, parsers
 import os, stat, errno
 
 _sha = util.sha1
 
 # This avoids a collision between a file named foo and a dir named
 # foo.i or foo.d
-def encodedir(path):
+def _encodedir(path):
     '''
-    >>> encodedir('data/foo.i')
+    >>> _encodedir('data/foo.i')
     'data/foo.i'
-    >>> encodedir('data/foo.i/bla.i')
+    >>> _encodedir('data/foo.i/bla.i')
     'data/foo.i.hg/bla.i'
-    >>> encodedir('data/foo.i.hg/bla.i')
+    >>> _encodedir('data/foo.i.hg/bla.i')
     'data/foo.i.hg.hg/bla.i'
-    >>> encodedir('data/foo.i\\ndata/foo.i/bla.i\\ndata/foo.i.hg/bla.i\\n')
+    >>> _encodedir('data/foo.i\\ndata/foo.i/bla.i\\ndata/foo.i.hg/bla.i\\n')
     'data/foo.i\\ndata/foo.i.hg/bla.i\\ndata/foo.i.hg.hg/bla.i\\n'
     '''
     return (path
@@ -29,6 +29,8 @@
             .replace(".i/", ".i.hg/")
             .replace(".d/", ".d.hg/"))
 
+encodedir = getattr(parsers, 'encodedir', _encodedir)
+
 def decodedir(path):
     '''
     >>> decodedir('data/foo.i')