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)
--- 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')