py/{objfloat,objcomplex}: Optimise MP_UNARY_OP_ABS by reusing variables.

This commit is contained in:
Damien George
2017-09-18 14:31:03 +10:00
parent 9dce823cfd
commit fdb2aa81b7
2 changed files with 4 additions and 8 deletions

View File

@@ -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;
}