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/modbuiltins.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/modbuiltins.c')
-rw-r--r-- | py/modbuiltins.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/py/modbuiltins.c b/py/modbuiltins.c index 1e91d43211..76274c2393 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -272,8 +272,8 @@ STATIC mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) { MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_divmod_obj, mp_builtin_divmod); STATIC mp_obj_t mp_builtin_hash(mp_obj_t o_in) { - // TODO hash will generally overflow small integer; can we safely truncate it? - return mp_obj_new_int(mp_obj_hash(o_in)); + // result is guaranteed to be a (small) int + return mp_unary_op(MP_UNARY_OP_HASH, o_in); } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_hash_obj, mp_builtin_hash); |