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/objfun.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'py/objfun.c') diff --git a/py/objfun.c b/py/objfun.c index ced8cebb0e..487c432a61 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -98,6 +98,7 @@ const mp_obj_type_t mp_type_fun_builtin = { { &mp_type_type }, .name = MP_QSTR_function, .call = fun_builtin_call, + .unary_op = mp_generic_unary_op, }; /******************************************************************************/ @@ -314,6 +315,7 @@ const mp_obj_type_t mp_type_fun_bc = { .print = fun_bc_print, #endif .call = fun_bc_call, + .unary_op = mp_generic_unary_op, #if MICROPY_PY_FUNCTION_ATTRS .attr = fun_bc_attr, #endif @@ -366,6 +368,7 @@ STATIC const mp_obj_type_t mp_type_fun_native = { { &mp_type_type }, .name = MP_QSTR_function, .call = fun_native_call, + .unary_op = mp_generic_unary_op, }; mp_obj_t mp_obj_new_fun_native(mp_uint_t scope_flags, mp_uint_t n_pos_args, mp_uint_t n_kwonly_args, mp_obj_t def_args_in, mp_obj_t def_kw_args, const void *fun_data) { @@ -421,6 +424,7 @@ STATIC const mp_obj_type_t mp_type_fun_viper = { { &mp_type_type }, .name = MP_QSTR_function, .call = fun_viper_call, + .unary_op = mp_generic_unary_op, }; mp_obj_t mp_obj_new_fun_viper(mp_uint_t n_args, void *fun_data, mp_uint_t type_sig) { @@ -533,6 +537,7 @@ STATIC const mp_obj_type_t mp_type_fun_asm = { { &mp_type_type }, .name = MP_QSTR_function, .call = fun_asm_call, + .unary_op = mp_generic_unary_op, }; mp_obj_t mp_obj_new_fun_asm(mp_uint_t n_args, void *fun_data) { -- cgit v1.2.3