From 09a0c64bce93f5ebcea82e81b4b07ddd7ff76cc7 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 30 Jan 2014 10:05:33 +0000 Subject: py: Improve __bool__ and __len__ dispatch; add slots for them. --- py/runtime.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'py/runtime.c') diff --git a/py/runtime.c b/py/runtime.c index 6b3c8dc1d0..b1027de932 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -304,23 +304,23 @@ void rt_assign_inline_asm_code(uint unique_code_id, void *fun, uint len, int n_a int rt_is_true(mp_obj_t arg) { DEBUG_OP_printf("is true %p\n", arg); - if (MP_OBJ_IS_SMALL_INT(arg)) { + if (arg == mp_const_false) { + return 0; + } else if (arg == mp_const_true) { + return 1; + } else if (arg == mp_const_none) { + return 0; + } else if (MP_OBJ_IS_SMALL_INT(arg)) { if (MP_OBJ_SMALL_INT_VALUE(arg) == 0) { return 0; } else { return 1; } - } else if (arg == mp_const_none) { - return 0; - } else if (arg == mp_const_false) { - return 0; - } else if (arg == mp_const_true) { - return 1; } else { mp_obj_type_t *type = mp_obj_get_type(arg); if (type->unary_op != NULL) { mp_obj_t result = type->unary_op(RT_UNARY_OP_BOOL, arg); - if (result != NULL) { + if (result != MP_OBJ_NULL) { return result == mp_const_true; } } -- cgit v1.2.3