diff options
| author | Damien George | 2017-09-18 14:31:03 +1000 |
|---|---|---|
| committer | Damien George | 2017-09-18 14:31:03 +1000 |
| commit | fdb2aa81b7c7588d94ec59932781e14759045df0 (patch) | |
| tree | 56daffd7751dd646688239d0cee3455d46de6488 | |
| parent | 9dce823cfd0a9991350184f08a1373f3887134f4 (diff) | |
py/{objfloat,objcomplex}: Optimise MP_UNARY_OP_ABS by reusing variables.
| -rw-r--r-- | py/objcomplex.c | 7 | ||||
| -rw-r--r-- | py/objfloat.c | 5 |
2 files changed, 4 insertions, 8 deletions
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 } } diff --git a/py/objfloat.c b/py/objfloat.c index fefd78314..55a9379ff 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -163,10 +163,9 @@ STATIC mp_obj_t float_unary_op(mp_unary_op_t op, mp_obj_t o_in) { case MP_UNARY_OP_POSITIVE: return o_in; case MP_UNARY_OP_NEGATIVE: return mp_obj_new_float(-val); case MP_UNARY_OP_ABS: { - mp_float_t value = mp_obj_float_get(o_in); // TODO check for NaN etc - if (value < 0) { - return mp_obj_new_float(-value); + if (val < 0) { + return mp_obj_new_float(-val); } else { return o_in; } |
