py/makeqstrdefs.py: Optimise by using compiled re's so it runs faster.
By using pre-compiled regexs, using startswith(), and explicitly checking for empty lines (of which around 30% of the input lines are), automatic qstr extraction is speed up by about 10%.
This commit is contained in:
parent
06aa13c350
commit
f6a1f18603
@ -24,12 +24,16 @@ def write_out(fname, output):
|
|||||||
f.write("\n".join(output) + "\n")
|
f.write("\n".join(output) + "\n")
|
||||||
|
|
||||||
def process_file(f):
|
def process_file(f):
|
||||||
|
re_line = re.compile(r"#[line]*\s\d+\s\"([^\"]+)\"")
|
||||||
|
re_qstr = re.compile(r'MP_QSTR_[_a-zA-Z0-9]+')
|
||||||
output = []
|
output = []
|
||||||
last_fname = None
|
last_fname = None
|
||||||
for line in f:
|
for line in f:
|
||||||
|
if line.isspace():
|
||||||
|
continue
|
||||||
# match gcc-like output (# n "file") and msvc-like output (#line n "file")
|
# match gcc-like output (# n "file") and msvc-like output (#line n "file")
|
||||||
if line and (line[0:2] == "# " or line[0:5] == "#line"):
|
if line.startswith(('# ', '#line')):
|
||||||
m = re.match(r"#[line]*\s\d+\s\"([^\"]+)\"", line)
|
m = re_line.match(line)
|
||||||
assert m is not None
|
assert m is not None
|
||||||
fname = m.group(1)
|
fname = m.group(1)
|
||||||
if not fname.endswith(".c"):
|
if not fname.endswith(".c"):
|
||||||
@ -39,7 +43,7 @@ def process_file(f):
|
|||||||
output = []
|
output = []
|
||||||
last_fname = fname
|
last_fname = fname
|
||||||
continue
|
continue
|
||||||
for match in re.findall(r'MP_QSTR_[_a-zA-Z0-9]+', line):
|
for match in re_qstr.findall(line):
|
||||||
name = match.replace('MP_QSTR_', '')
|
name = match.replace('MP_QSTR_', '')
|
||||||
if name not in QSTRING_BLACK_LIST:
|
if name not in QSTRING_BLACK_LIST:
|
||||||
output.append('Q(' + name + ')')
|
output.append('Q(' + name + ')')
|
||||||
|
Loading…
Reference in New Issue
Block a user