summaryrefslogtreecommitdiffstatshomepage
path: root/py/makeqstrdefs.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-03-16 23:54:06 +1100
committerDamien George <damien.p.george@gmail.com>2018-03-16 23:54:06 +1100
commitf6a1f18603de5c4d2321bcf4f967df298850e3f6 (patch)
tree6255444708454c8e979822219e44cb6cef83a477 /py/makeqstrdefs.py
parent06aa13c350af0f3910b2d99303548f31a85c0d9c (diff)
downloadmicropython-f6a1f18603de5c4d2321bcf4f967df298850e3f6.tar.gz
micropython-f6a1f18603de5c4d2321bcf4f967df298850e3f6.zip
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%.
Diffstat (limited to 'py/makeqstrdefs.py')
-rw-r--r--py/makeqstrdefs.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/py/makeqstrdefs.py b/py/makeqstrdefs.py
index 525dec1973..176440136d 100644
--- a/py/makeqstrdefs.py
+++ b/py/makeqstrdefs.py
@@ -24,12 +24,16 @@ def write_out(fname, output):
f.write("\n".join(output) + "\n")
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 = []
last_fname = None
for line in f:
+ if line.isspace():
+ continue
# match gcc-like output (# n "file") and msvc-like output (#line n "file")
- if line and (line[0:2] == "# " or line[0:5] == "#line"):
- m = re.match(r"#[line]*\s\d+\s\"([^\"]+)\"", line)
+ if line.startswith(('# ', '#line')):
+ m = re_line.match(line)
assert m is not None
fname = m.group(1)
if not fname.endswith(".c"):
@@ -39,7 +43,7 @@ def process_file(f):
output = []
last_fname = fname
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_', '')
if name not in QSTRING_BLACK_LIST:
output.append('Q(' + name + ')')