From c2a4e4effc81d8ab21bb014e34355643e5ca0da2 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 11 May 2015 12:25:19 +0000 Subject: py: Convert hash API to use MP_UNARY_OP_HASH instead of ad-hoc function. Hashing is now done using mp_unary_op function with MP_UNARY_OP_HASH as the operator argument. Hashing for int, str and bytes still go via fast-path in mp_unary_op since they are the most common objects which need to be hashed. This lead to quite a bit of code cleanup, and should be more efficient if anything. It saves 176 bytes code space on Thumb2, and 360 bytes on x86. The only loss is that the error message "unhashable type" is now the more generic "unsupported type for __hash__". --- py/objnone.c | 1 + 1 file changed, 1 insertion(+) (limited to 'py/objnone.c') diff --git a/py/objnone.c b/py/objnone.c index d47452bb4d..69eab03fe2 100644 --- a/py/objnone.c +++ b/py/objnone.c @@ -47,6 +47,7 @@ STATIC mp_obj_t none_unary_op(mp_uint_t op, mp_obj_t o_in) { (void)o_in; switch (op) { case MP_UNARY_OP_BOOL: return mp_const_false; + case MP_UNARY_OP_HASH: return MP_OBJ_NEW_SMALL_INT((mp_uint_t)o_in); default: return MP_OBJ_NULL; // op not supported } } -- cgit v1.2.3