aboutsummaryrefslogtreecommitdiff
path: root/py/objtype.c
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2021-08-19 22:46:40 +1000
committerDamien George <damien@micropython.org>2021-09-16 16:02:15 +1000
commit7b89ad8dbf432ab51eea6d138e179bf51394c786 (patch)
treea94bbd7cd3cdb8e297a6582b7a160789241a8c1e /py/objtype.c
parent910e060f93c02c51a498f57ef77ccbe02566855b (diff)
py/vm: Add a fast path for LOAD_ATTR on instance types.
When the LOAD_ATTR opcode is executed there are quite a few different cases that have to be handled, but the common case is accessing a member on an instance type. Typically, built-in types provide methods which is why this is common. Fortunately, for this specific case, if the member is found in the member map then there's no further processing. This optimisation does a relatively cheap check (type is instance) and then forwards directly to the member map lookup, falling back to the regular path if necessary. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'py/objtype.c')
-rw-r--r--py/objtype.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/py/objtype.c b/py/objtype.c
index 508bab99d..0977a67ce 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -579,6 +579,7 @@ STATIC void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *des
assert(mp_obj_is_instance_type(mp_obj_get_type(self_in)));
mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in);
+ // Note: This is fast-path'ed in the VM for the MP_BC_LOAD_ATTR operation.
mp_map_elem_t *elem = mp_map_lookup(&self->members, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP);
if (elem != NULL) {
// object member, always treated as a value