mp_load_name(): Optimize for outer scope where locals == globals.
This commit is contained in:
parent
e3f58c8380
commit
a0d32991ed
14
py/runtime.c
14
py/runtime.c
@ -93,13 +93,15 @@ mp_obj_t mp_load_const_bytes(qstr qstr) {
|
||||
|
||||
mp_obj_t mp_load_name(qstr qstr) {
|
||||
// logic: search locals, globals, builtins
|
||||
DEBUG_OP_printf("load name %s\n", qstr_str(qstr));
|
||||
mp_map_elem_t *elem = mp_map_lookup(map_locals, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP);
|
||||
if (elem != NULL) {
|
||||
return elem->value;
|
||||
} else {
|
||||
return mp_load_global(qstr);
|
||||
DEBUG_OP_printf("load name %s\n", map_locals, qstr_str(qstr));
|
||||
// If we're at the outer scope (locals == globals), dispatch to load_global right away
|
||||
if (map_locals != map_globals) {
|
||||
mp_map_elem_t *elem = mp_map_lookup(map_locals, MP_OBJ_NEW_QSTR(qstr), MP_MAP_LOOKUP);
|
||||
if (elem != NULL) {
|
||||
return elem->value;
|
||||
}
|
||||
}
|
||||
return mp_load_global(qstr);
|
||||
}
|
||||
|
||||
mp_obj_t mp_load_global(qstr qstr) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user