diff options
author | John R. Lenton <jlenton@gmail.com> | 2014-01-06 17:54:04 +0000 |
---|---|---|
committer | John R. Lenton <jlenton@gmail.com> | 2014-01-07 22:51:08 +0000 |
commit | 7d21d516d2eb77242c8ade4ae83f0d438e86f072 (patch) | |
tree | b39a629c84d2c9642706d993ebc1c3a6dc96fdaf /py | |
parent | 4ce6ceadcad294a62f6fb2b23da262dc5cad0793 (diff) | |
download | micropython-7d21d516d2eb77242c8ade4ae83f0d438e86f072.tar.gz micropython-7d21d516d2eb77242c8ade4ae83f0d438e86f072.zip |
make dict_len use the map's used count
Diffstat (limited to 'py')
-rw-r--r-- | py/objdict.c | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/py/objdict.c b/py/objdict.c index 1a5e162e56..951e1ec068 100644 --- a/py/objdict.c +++ b/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) { |