diff options
author | Damien George <damien.p.george@gmail.com> | 2015-05-11 12:25:19 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-05-12 22:46:02 +0100 |
commit | c2a4e4effc81d8ab21bb014e34355643e5ca0da2 (patch) | |
tree | d08f5921b2053c5d49ba7b10688eb8a771ddd7d0 /py/objfun.c | |
parent | 6738c1dded8e436686f85008ec0a4fc47406ab7a (diff) | |
download | micropython-c2a4e4effc81d8ab21bb014e34355643e5ca0da2.tar.gz micropython-c2a4e4effc81d8ab21bb014e34355643e5ca0da2.zip |
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__".
Diffstat (limited to 'py/objfun.c')
-rw-r--r-- | py/objfun.c | 5 |
1 files changed, 5 insertions, 0 deletions
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) { |