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/objcomplex.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'py/objcomplex.c') diff --git a/py/objcomplex.c b/py/objcomplex.c index 1415068438..f4a68851a5 100644 --- a/py/objcomplex.c +++ b/py/objcomplex.c @@ -141,7 +141,11 @@ STATIC mp_obj_t complex_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in return mp_obj_complex_binary_op(op, lhs->real, lhs->imag, rhs_in); } -STATIC void complex_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +STATIC void complex_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { + if (dest[0] != MP_OBJ_NULL) { + // not load attribute + return; + } mp_obj_complex_t *self = self_in; if (attr == MP_QSTR_real) { dest[0] = mp_obj_new_float(self->real); @@ -157,7 +161,7 @@ const mp_obj_type_t mp_type_complex = { .make_new = complex_make_new, .unary_op = complex_unary_op, .binary_op = complex_binary_op, - .load_attr = complex_load_attr, + .attr = complex_attr, }; mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag) { -- cgit v1.2.3