comparison contrib/check-code.py @ 29398:2a54cf92c773

check-code: build translation table for repquote in global for efficiency Rebuilding translation table (256 size) at each repquote() invocations is redundant. For example, this patch decreases user time of command invocation below from 18.297s to 13.445s (about -27%) on a Linux box. This command is main part of test-check-code.t. hg locate | xargs python contrib/check-code.py --warnings --per-file=0 This patch adds "_repquote" prefix to functions and variables factored out from repquote() to avoid conflict of name in the future.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 21 Jun 2016 00:50:39 +0900
parents 844f72885fb9
children 7dce56174916
comparison
equal deleted inserted replaced
29397:844f72885fb9 29398:2a54cf92c773
48 return re2.compile(pat) 48 return re2.compile(pat)
49 except re2.error: 49 except re2.error:
50 pass 50 pass
51 return re.compile(pat) 51 return re.compile(pat)
52 52
53 # check "rules depending on implementation of repquote()" in each
54 # patterns (especially pypats), before changing around repquote()
55 _repquotefixedmap = {' ': ' ', '\n': '\n', '.': 'p', ':': 'q',
56 '%': '%', '\\': 'b', '*': 'A', '+': 'P', '-': 'M'}
57 def _repquoteencodechr(i):
58 if i > 255:
59 return 'u'
60 c = chr(i)
61 if c in _repquotefixedmap:
62 return _repquotefixedmap[c]
63 if c.isalpha():
64 return 'x'
65 if c.isdigit():
66 return 'n'
67 return 'o'
68 _repquotett = ''.join(_repquoteencodechr(i) for i in xrange(256))
69
53 def repquote(m): 70 def repquote(m):
54 # check "rules depending on implementation of repquote()" in each
55 # patterns (especially pypats), before changing this function
56 fixedmap = {' ': ' ', '\n': '\n', '.': 'p', ':': 'q',
57 '%': '%', '\\': 'b', '*': 'A', '+': 'P', '-': 'M'}
58 def encodechr(i):
59 if i > 255:
60 return 'u'
61 c = chr(i)
62 if c in fixedmap:
63 return fixedmap[c]
64 if c.isalpha():
65 return 'x'
66 if c.isdigit():
67 return 'n'
68 return 'o'
69 t = m.group('text') 71 t = m.group('text')
70 tt = ''.join(encodechr(i) for i in xrange(256)) 72 t = t.translate(_repquotett)
71 t = t.translate(tt)
72 return m.group('quote') + t + m.group('quote') 73 return m.group('quote') + t + m.group('quote')
73 74
74 def reppython(m): 75 def reppython(m):
75 comment = m.group('comment') 76 comment = m.group('comment')
76 if comment: 77 if comment: