diff options
author | Damien George <damien.p.george@gmail.com> | 2015-04-01 14:10:50 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-04-11 16:54:37 +0100 |
commit | b1bbe966c408901ae64ea8c8b468694c47d05b1a (patch) | |
tree | 46025c34daf602aeb1e8def41d1e01f0750b6d13 /py/runtime.c | |
parent | d07ccc5a394d0252ffbc227509ed2134465c215a (diff) | |
download | micropython-b1bbe966c408901ae64ea8c8b468694c47d05b1a.tar.gz micropython-b1bbe966c408901ae64ea8c8b468694c47d05b1a.zip |
py: Combine load_attr and store_attr type methods into one (attr).
This simplifies the API for objects and reduces code size (by around 400
bytes on Thumb2, and around 2k on x86). Performance impact was measured
with Pystone score, but change was barely noticeable.
Diffstat (limited to 'py/runtime.c')
-rw-r--r-- | py/runtime.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/py/runtime.c b/py/runtime.c index 2bb9a02641..b04a4af139 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -917,9 +917,9 @@ void mp_load_method_maybe(mp_obj_t obj, qstr attr, mp_obj_t *dest) { dest[0] = (mp_obj_t)&mp_builtin_next_obj; dest[1] = obj; - } else if (type->load_attr != NULL) { + } else if (type->attr != NULL) { // this type can do its own load, so call it - type->load_attr(obj, attr, dest); + type->attr(obj, attr, dest); } else if (type->locals_dict != NULL) { // generic method lookup @@ -961,8 +961,11 @@ void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest) { void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) { DEBUG_OP_printf("store attr %p.%s <- %p\n", base, qstr_str(attr), value); mp_obj_type_t *type = mp_obj_get_type(base); - if (type->store_attr != NULL) { - if (type->store_attr(base, attr, value)) { + if (type->attr != NULL) { + mp_obj_t dest[2] = {MP_OBJ_SENTINEL, value}; + type->attr(base, attr, dest); + if (dest[0] == MP_OBJ_NULL) { + // success return; } } |