make dict_len use the map's used count
This commit is contained in:
parent
4ce6ceadca
commit
7d21d516d2
12
py/objdict.c
12
py/objdict.c
@ -128,12 +128,12 @@ static mp_obj_t dict_clear(mp_obj_t self_in) {
|
||||
|
||||
return mp_const_none;
|
||||
}
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(dict_clear_obj, dict_clear);
|
||||
|
||||
|
||||
/******************************************************************************/
|
||||
/* dict constructors & etc */
|
||||
|
||||
static MP_DEFINE_CONST_FUN_OBJ_1(dict_clear_obj, dict_clear);
|
||||
|
||||
const mp_obj_type_t dict_type = {
|
||||
{ &mp_const_type },
|
||||
"dict",
|
||||
@ -156,13 +156,7 @@ mp_obj_t mp_obj_new_dict(int n_args) {
|
||||
|
||||
uint mp_obj_dict_len(mp_obj_t self_in) {
|
||||
mp_obj_dict_t *self = self_in;
|
||||
uint len = 0;
|
||||
for (int i = 0; i < self->map.alloc; i++) {
|
||||
if (self->map.table[i].key != NULL) {
|
||||
len += 1;
|
||||
}
|
||||
}
|
||||
return len;
|
||||
return self->map.used;
|
||||
}
|
||||
|
||||
mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value) {
|
||||
|
Loading…
Reference in New Issue
Block a user