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/objexcept.c | |
parent | d07ccc5a394d0252ffbc227509ed2134465c215a (diff) |
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/objexcept.c')
-rw-r--r-- | py/objexcept.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/py/objexcept.c b/py/objexcept.c index 987a54fda..2d23f160a 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -140,7 +140,11 @@ mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in) { } } -STATIC void exception_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +STATIC void exception_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { + if (dest[0] != MP_OBJ_NULL) { + // not load attribute + return; + } mp_obj_exception_t *self = self_in; if (attr == MP_QSTR_args) { dest[0] = self->args; @@ -168,7 +172,7 @@ const mp_obj_type_t mp_type_BaseException = { .name = MP_QSTR_BaseException, .print = mp_obj_exception_print, .make_new = mp_obj_exception_make_new, - .load_attr = exception_load_attr, + .attr = exception_attr, .locals_dict = (mp_obj_t)&exc_locals_dict, }; @@ -181,7 +185,7 @@ const mp_obj_type_t mp_type_ ## exc_name = { \ .name = MP_QSTR_ ## exc_name, \ .print = mp_obj_exception_print, \ .make_new = mp_obj_exception_make_new, \ - .load_attr = exception_load_attr, \ + .attr = exception_attr, \ .bases_tuple = (mp_obj_t)&mp_type_ ## base_name ## _base_tuple, \ }; |