Skip to content

Commit

Permalink
NewPyBuildSupport: Only compile expr once for exception table lines
Browse files Browse the repository at this point in the history
Signed-off-by: Gabe Goodhart <[email protected]>
  • Loading branch information
gabe-l-hart committed Feb 19, 2024
1 parent a33eaa3 commit e3d2a51
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion import_tracker/import_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e3d2a51

Please sign in to comment.