Mercurial > hg
comparison mercurial/store.py @ 17570:f53a7b256ca6
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).
author | Adrian Buehlmann <adrian@cadifra.com> |
---|---|
date | Sat, 15 Sep 2012 21:41:09 +0200 |
parents | e9af2134825c |
children | 7ed972a9e7a9 |
comparison
equal
deleted
inserted
replaced
17569:e9af2134825c | 17570:f53a7b256ca6 |
---|---|
116 cmap[chr(x)] = chr(x).lower() | 116 cmap[chr(x)] = chr(x).lower() |
117 return lambda s: "".join([cmap[c] for c in s]) | 117 return lambda s: "".join([cmap[c] for c in s]) |
118 | 118 |
119 lowerencode = _buildlowerencodefun() | 119 lowerencode = _buildlowerencodefun() |
120 | 120 |
121 _winreservednames = '''con prn aux nul | 121 # Windows reserved names: con, prn, aux, nul, com1..com9, lpt1..lpt9 |
122 com1 com2 com3 com4 com5 com6 com7 com8 com9 | 122 _winres3 = ('aux', 'con', 'prn', 'nul') # length 3 |
123 lpt1 lpt2 lpt3 lpt4 lpt5 lpt6 lpt7 lpt8 lpt9'''.split() | 123 _winres4 = ('com', 'lpt') # length 4 (with trailing 1..9) |
124 def _auxencode(path, dotencode): | 124 def _auxencode(path, dotencode): |
125 ''' | 125 ''' |
126 Encodes filenames containing names reserved by Windows or which end in | 126 Encodes filenames containing names reserved by Windows or which end in |
127 period or space. Does not touch other single reserved characters c. | 127 period or space. Does not touch other single reserved characters c. |
128 Specifically, c in '\\:*?"<>|' or ord(c) <= 31 are *not* encoded here. | 128 Specifically, c in '\\:*?"<>|' or ord(c) <= 31 are *not* encoded here. |
142 '~20.foo' | 142 '~20.foo' |
143 ''' | 143 ''' |
144 res = [] | 144 res = [] |
145 for n in path.split('/'): | 145 for n in path.split('/'): |
146 if n: | 146 if n: |
147 base = n.split('.')[0] | 147 if dotencode and n[0] in '. ': |
148 if base and (base in _winreservednames): | 148 n = "~%02x" % ord(n[0]) + n[1:] |
149 # encode third letter ('aux' -> 'au~78') | 149 else: |
150 ec = "~%02x" % ord(n[2]) | 150 l = n.find('.') |
151 n = n[0:2] + ec + n[3:] | 151 if l == -1: |
152 l = len(n) | |
153 if ((l == 3 and n[:3] in _winres3) or | |
154 (l == 4 and n[3] <= '9' and n[3] >= '1' | |
155 and n[:3] in _winres4)): | |
156 # encode third letter ('aux' -> 'au~78') | |
157 ec = "~%02x" % ord(n[2]) | |
158 n = n[0:2] + ec + n[3:] | |
152 if n[-1] in '. ': | 159 if n[-1] in '. ': |
153 # encode last period or space ('foo...' -> 'foo..~2e') | 160 # encode last period or space ('foo...' -> 'foo..~2e') |
154 n = n[:-1] + "~%02x" % ord(n[-1]) | 161 n = n[:-1] + "~%02x" % ord(n[-1]) |
155 if dotencode and n[0] in '. ': | |
156 n = "~%02x" % ord(n[0]) + n[1:] | |
157 res.append(n) | 162 res.append(n) |
158 return '/'.join(res) | 163 return '/'.join(res) |
159 | 164 |
160 _maxstorepathlen = 120 | 165 _maxstorepathlen = 120 |
161 _dirprefixlen = 8 | 166 _dirprefixlen = 8 |