summaryrefslogtreecommitdiffstatshomepage
path: root/py/objcomplex.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-04-01 14:10:50 +0000
committerDamien George <damien.p.george@gmail.com>2015-04-11 16:54:37 +0100
commitb1bbe966c408901ae64ea8c8b468694c47d05b1a (patch)
tree46025c34daf602aeb1e8def41d1e01f0750b6d13 /py/objcomplex.c
parentd07ccc5a394d0252ffbc227509ed2134465c215a (diff)
downloadmicropython-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/objcomplex.c')
-rw-r--r--py/objcomplex.c8
1 files changed, 6 insertions, 2 deletions
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) {