[PATCH 03 of 10] store: optimze _auxencode() a bit by grouping the reserved names by length

Adrian Buehlmann adrian at cadifra.com
Sat Sep 15 16:01:44 CDT 2012


# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1347738069 -7200
# Node ID f53a7b256ca690d22259e966cf4ef52938bd58aa
# Parent  e9af2134825c468269ed5f22af001dd58ec1d6cd
store: optimze _auxencode() a bit by grouping the reserved names by length

This reduces perffncacheencode wall time on Windows 7 x64 for my netbeans clone
here from 4.3 to 4.0 (7% faster).

diff --git a/mercurial/store.py b/mercurial/store.py
--- a/mercurial/store.py
+++ b/mercurial/store.py
@@ -118,9 +118,9 @@
 
 lowerencode = _buildlowerencodefun()
 
-_winreservednames = '''con prn aux nul
-    com1 com2 com3 com4 com5 com6 com7 com8 com9
-    lpt1 lpt2 lpt3 lpt4 lpt5 lpt6 lpt7 lpt8 lpt9'''.split()
+# Windows reserved names: con, prn, aux, nul, com1..com9, lpt1..lpt9
+_winres3 = ('aux', 'con', 'prn', 'nul') # length 3
+_winres4 = ('com', 'lpt')               # length 4 (with trailing 1..9)
 def _auxencode(path, dotencode):
     '''
     Encodes filenames containing names reserved by Windows or which end in
@@ -144,16 +144,21 @@
     res = []
     for n in path.split('/'):
         if n:
-            base = n.split('.')[0]
-            if base and (base in _winreservednames):
-                # encode third letter ('aux' -> 'au~78')
-                ec = "~%02x" % ord(n[2])
-                n = n[0:2] + ec + n[3:]
+            if dotencode and n[0] in '. ':
+                n = "~%02x" % ord(n[0]) + n[1:]
+            else:
+                l = n.find('.')
+                if l == -1:
+                    l = len(n)
+                if ((l == 3 and n[:3] in _winres3) or
+                    (l == 4 and n[3] <= '9' and n[3] >= '1'
+                            and n[:3] in _winres4)):
+                    # encode third letter ('aux' -> 'au~78')
+                    ec = "~%02x" % ord(n[2])
+                    n = n[0:2] + ec + n[3:]
             if n[-1] in '. ':
                 # encode last period or space ('foo...' -> 'foo..~2e')
                 n = n[:-1] + "~%02x" % ord(n[-1])
-            if dotencode and n[0] in '. ':
-                n = "~%02x" % ord(n[0]) + n[1:]
         res.append(n)
     return '/'.join(res)
 


More information about the Mercurial-devel mailing list