mirror of
https://github.com/licsber/micropython.git
synced 2024-09-20 00:50:24 +08:00
py/map: Don't include ordered-dict mutating code when not needed.
This commit is contained in:
parent
f5fb68e94f
commit
136cb7f27c
6
py/map.c
6
py/map.c
@ -170,6 +170,7 @@ mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t
|
|||||||
if (map->is_ordered) {
|
if (map->is_ordered) {
|
||||||
for (mp_map_elem_t *elem = &map->table[0], *top = &map->table[map->used]; elem < top; elem++) {
|
for (mp_map_elem_t *elem = &map->table[0], *top = &map->table[map->used]; elem < top; elem++) {
|
||||||
if (elem->key == index || (!compare_only_ptrs && mp_obj_equal(elem->key, index))) {
|
if (elem->key == index || (!compare_only_ptrs && mp_obj_equal(elem->key, index))) {
|
||||||
|
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
||||||
if (MP_UNLIKELY(lookup_kind == MP_MAP_LOOKUP_REMOVE_IF_FOUND)) {
|
if (MP_UNLIKELY(lookup_kind == MP_MAP_LOOKUP_REMOVE_IF_FOUND)) {
|
||||||
// remove the found element by moving the rest of the array down
|
// remove the found element by moving the rest of the array down
|
||||||
mp_obj_t value = elem->value;
|
mp_obj_t value = elem->value;
|
||||||
@ -180,9 +181,11 @@ mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t
|
|||||||
elem->key = MP_OBJ_NULL;
|
elem->key = MP_OBJ_NULL;
|
||||||
elem->value = value;
|
elem->value = value;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
||||||
if (MP_LIKELY(lookup_kind != MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)) {
|
if (MP_LIKELY(lookup_kind != MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -198,6 +201,9 @@ mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t
|
|||||||
map->all_keys_are_qstrs = 0;
|
map->all_keys_are_qstrs = 0;
|
||||||
}
|
}
|
||||||
return elem;
|
return elem;
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// map is a hash table (not an ordered array), so do a hash lookup
|
// map is a hash table (not an ordered array), so do a hash lookup
|
||||||
|
Loading…
Reference in New Issue
Block a user