summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2016-09-30 16:46:31 +1000
committerDamien George <damien.p.george@gmail.com>2016-09-30 17:02:06 +1000
commiteca1408f16beeeb06e2eb16410545a29b7064f20 (patch)
treeccb61488b320c93d5deea77e41f2ae26cbf69a3b /py
parent3be4f886ce2ab5bd625e0d7ad29ba827844df749 (diff)
downloadmicropython-eca1408f16beeeb06e2eb16410545a29b7064f20.tar.gz
micropython-eca1408f16beeeb06e2eb16410545a29b7064f20.zip
py/objbool: Defer bool's unary op implementation to small int.
Similar to how binary op already works. Common unary operations already have fast paths for bool so there's no need to have explicit handling of ops in bool_unary_op, especially since they have the same behaviour as integers.
Diffstat (limited to 'py')
-rw-r--r--py/objbool.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/py/objbool.c b/py/objbool.c
index 8882a835d3..2a086020de 100644
--- a/py/objbool.c
+++ b/py/objbool.c
@@ -66,16 +66,11 @@ STATIC mp_obj_t bool_make_new(const mp_obj_type_t *type_in, size_t n_args, size_
}
STATIC mp_obj_t bool_unary_op(mp_uint_t op, mp_obj_t o_in) {
- mp_int_t value = ((mp_obj_bool_t*)MP_OBJ_TO_PTR(o_in))->value;
- switch (op) {
- case MP_UNARY_OP_BOOL: return o_in;
- // needs to hash to the same value as if converting to an integer
- case MP_UNARY_OP_HASH: return MP_OBJ_NEW_SMALL_INT(value);
- case MP_UNARY_OP_POSITIVE: return MP_OBJ_NEW_SMALL_INT(value);
- case MP_UNARY_OP_NEGATIVE: return MP_OBJ_NEW_SMALL_INT(-value);
- case MP_UNARY_OP_INVERT: return MP_OBJ_NEW_SMALL_INT(~value);
- default: return MP_OBJ_NULL; // op not supported
+ if (op == MP_UNARY_OP_LEN) {
+ return MP_OBJ_NULL;
}
+ mp_obj_bool_t *self = MP_OBJ_TO_PTR(o_in);
+ return mp_unary_op(op, MP_OBJ_NEW_SMALL_INT(self->value));
}
STATIC mp_obj_t bool_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {