[PATCH 2 of 2] store: use fast C implementation of encodedir() if it's available

Adrian Buehlmann adrian at cadifra.com
Tue Sep 18 05:02:18 CDT 2012


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1347961456 -7200
# Node ID c4d75ee7328e012ff0a1efa6c1486771cd02dbc2
# Parent  b62927686fa75898548e1c6e80e70dd825db5853
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)

diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -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')


More information about the Mercurial-devel mailing list