mirror of
https://github.com/licsber/micropython.git
synced 2024-09-20 09:00:23 +08:00
py: Make bytes type hashable.
This commit is contained in:
parent
73b7027b83
commit
f130ca1f60
2
py/obj.c
2
py/obj.c
@ -110,7 +110,7 @@ machine_int_t mp_obj_hash(mp_obj_t o_in) {
|
|||||||
return 1; // needs to hash to same as the integer 1, since True==1
|
return 1; // needs to hash to same as the integer 1, since True==1
|
||||||
} else if (MP_OBJ_IS_SMALL_INT(o_in)) {
|
} else if (MP_OBJ_IS_SMALL_INT(o_in)) {
|
||||||
return MP_OBJ_SMALL_INT_VALUE(o_in);
|
return MP_OBJ_SMALL_INT_VALUE(o_in);
|
||||||
} else if (MP_OBJ_IS_STR(o_in)) {
|
} else if (MP_OBJ_IS_STR(o_in) || MP_OBJ_IS_TYPE(o_in, &mp_type_bytes)) {
|
||||||
return mp_obj_str_get_hash(o_in);
|
return mp_obj_str_get_hash(o_in);
|
||||||
} else if (MP_OBJ_IS_TYPE(o_in, &mp_type_NoneType)) {
|
} else if (MP_OBJ_IS_TYPE(o_in, &mp_type_NoneType)) {
|
||||||
return (machine_int_t)o_in;
|
return (machine_int_t)o_in;
|
||||||
|
@ -1480,7 +1480,8 @@ STATIC void bad_implicit_conversion(mp_obj_t self_in) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint mp_obj_str_get_hash(mp_obj_t self_in) {
|
uint mp_obj_str_get_hash(mp_obj_t self_in) {
|
||||||
if (MP_OBJ_IS_STR(self_in)) {
|
// TODO: This has too big overhead for hash accessor
|
||||||
|
if (MP_OBJ_IS_STR(self_in) || MP_OBJ_IS_TYPE(self_in, &mp_type_bytes)) {
|
||||||
GET_STR_HASH(self_in, h);
|
GET_STR_HASH(self_in, h);
|
||||||
return h;
|
return h;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user