From b1bbe966c408901ae64ea8c8b468694c47d05b1a Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 1 Apr 2015 14:10:50 +0000 Subject: 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. --- py/objexcept.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'py/objexcept.c') 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, \ }; -- cgit v1.2.3