From fdb2aa81b7c7588d94ec59932781e14759045df0 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 18 Sep 2017 14:31:03 +1000 Subject: py/{objfloat,objcomplex}: Optimise MP_UNARY_OP_ABS by reusing variables. --- py/objcomplex.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'py/objcomplex.c') diff --git a/py/objcomplex.c b/py/objcomplex.c index e7a3c244a..088ad5211 100644 --- a/py/objcomplex.c +++ b/py/objcomplex.c @@ -124,11 +124,8 @@ STATIC mp_obj_t complex_unary_op(mp_unary_op_t op, mp_obj_t o_in) { case MP_UNARY_OP_HASH: return MP_OBJ_NEW_SMALL_INT(mp_float_hash(o->real) ^ mp_float_hash(o->imag)); case MP_UNARY_OP_POSITIVE: return o_in; case MP_UNARY_OP_NEGATIVE: return mp_obj_new_complex(-o->real, -o->imag); - case MP_UNARY_OP_ABS: { - mp_float_t real, imag; - mp_obj_complex_get(o_in, &real, &imag); - return mp_obj_new_float(MICROPY_FLOAT_C_FUN(sqrt)(real*real + imag*imag)); - } + case MP_UNARY_OP_ABS: + return mp_obj_new_float(MICROPY_FLOAT_C_FUN(sqrt)(o->real*o->real + o->imag*o->imag)); default: return MP_OBJ_NULL; // op not supported } } -- cgit v1.2.3