From e3d2a514821f4bd8750390ddeaeed1c290a47d77 Mon Sep 17 00:00:00 2001 From: Gabe Goodhart Date: Mon, 19 Feb 2024 14:00:58 -0700 Subject: [PATCH] NewPyBuildSupport: Only compile expr once for exception table lines Signed-off-by: Gabe Goodhart --- import_tracker/import_tracker.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/import_tracker/import_tracker.py b/import_tracker/import_tracker.py index 06faea6..5723fea 100644 --- a/import_tracker/import_tracker.py +++ b/import_tracker/import_tracker.py @@ -268,6 +268,10 @@ def _get_dylib_dir(): ] +# Regex for matching lines in the exception table +_exception_table_expr = re.compile(r" ([0-9]+) to ([0-9]+) -> [0-9]+ \[([0-9]+)\].*") + + def _mod_defined_in_init_file(mod: ModuleType) -> bool: """Determine if the given module is defined in an __init__.py[c]""" mod_file = getattr(mod, "__file__", None) @@ -357,7 +361,7 @@ def _get_exception_table(dis_lines: List[str]) -> Dict[int, int]: { int(m.group(1)): int(m.group(2)) for m in [ - re.match(r" ([0-9]+) to ([0-9]+) -> [0-9]+ \[([0-9]+)\].*", line) + _exception_table_expr.match(line) for line in dis_lines[table_start[0] + 1 :] ] if m and int(m.group(3)) == 0 and m.group(1) != m.group(2)