Skip to content

Commit

Permalink
Make inspect_enclosing_env branchless
Browse files Browse the repository at this point in the history
  • Loading branch information
cdonovick committed Jun 25, 2019
1 parent 715d92f commit f91ad62
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions magma/ast_utils.py
Expand Up @@ -64,14 +64,12 @@ def inspect_enclosing_env(fn):
def wrapped(*args, **kwargs):
stack = inspect.stack()
enclosing_env = {}
for i in range(0, len(stack)):
for key, value in stack[i].frame.f_locals.items():
if key not in enclosing_env:
enclosing_env[key] = value
for i in range(0, len(stack)):
for i in range(len(stack)-1, -1, -1):
for key, value in stack[i].frame.f_globals.items():
if key not in enclosing_env:
enclosing_env[key] = value
enclosing_env[key] = value
for i in range(len(stack)-1, -1, -1):
for key, value in stack[i].frame.f_locals.items():
enclosing_env[key] = value
return fn(enclosing_env, *args, **kwargs)
return wrapped

Expand Down

0 comments on commit f91ad62

Please sign in to comment.