Speed up warn.py about 30x by precompiling all the regular expressions.
This commit is contained in:
@@ -460,8 +460,8 @@ def dumpseverity(sev):
|
|||||||
|
|
||||||
def classifywarning(line):
|
def classifywarning(line):
|
||||||
for i in warnpatterns:
|
for i in warnpatterns:
|
||||||
for pat in i['patterns']:
|
for cpat in i['compiledpatterns']:
|
||||||
if re.match(pat, line):
|
if cpat.match(line):
|
||||||
i['members'].append(line)
|
i['members'].append(line)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
@@ -470,7 +470,12 @@ def classifywarning(line):
|
|||||||
# 2 or more concurrent compiles
|
# 2 or more concurrent compiles
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# precompiling every pattern speeds up parsing by about 30x
|
||||||
|
def compilepatterns():
|
||||||
|
for i in warnpatterns:
|
||||||
|
i['compiledpatterns'] = []
|
||||||
|
for pat in i['patterns']:
|
||||||
|
i['compiledpatterns'].append(re.compile(pat))
|
||||||
|
|
||||||
infile = open(sys.argv[1], 'r')
|
infile = open(sys.argv[1], 'r')
|
||||||
warnings = []
|
warnings = []
|
||||||
@@ -481,6 +486,7 @@ targetvariant = 'unknown'
|
|||||||
linecounter = 0
|
linecounter = 0
|
||||||
|
|
||||||
warningpattern = re.compile('.* warning:.*')
|
warningpattern = re.compile('.* warning:.*')
|
||||||
|
compilepatterns()
|
||||||
|
|
||||||
# read the log file and classify all the warnings
|
# read the log file and classify all the warnings
|
||||||
lastmatchedline = ''
|
lastmatchedline = ''
|
||||||
@@ -515,7 +521,3 @@ dumpseverity(severity.HARMLESS)
|
|||||||
dumpseverity(severity.UNKNOWN)
|
dumpseverity(severity.UNKNOWN)
|
||||||
dumpfixed()
|
dumpfixed()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user