Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions py/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ static void mp_map_rehash(mp_map_t *map) {
// - returns slot, with key non-null and value=MP_OBJ_NULL if it was added
// MP_MAP_LOOKUP_REMOVE_IF_FOUND behaviour:
// - returns NULL if not found, else the slot if was found in with key null and value non-null
mp_map_elem_t *mp_map_lookup_sub(mp_map_t * map, mp_obj_t index, mp_map_lookup_kind_t lookup_kind, bool compare_only_ptrs);

mp_map_elem_t *MICROPY_WRAP_MP_MAP_LOOKUP(mp_map_lookup)(mp_map_t * map, mp_obj_t index, mp_map_lookup_kind_t lookup_kind) {
// If the map is a fixed array then we must only be called for a lookup
assert(!map->is_fixed || lookup_kind == MP_MAP_LOOKUP);
Expand Down Expand Up @@ -188,6 +190,10 @@ mp_map_elem_t *MICROPY_WRAP_MP_MAP_LOOKUP(mp_map_lookup)(mp_map_t * map, mp_obj_
}
}

return mp_map_lookup_sub(map, index, lookup_kind, compare_only_ptrs);
}

mp_map_elem_t *mp_map_lookup_sub(mp_map_t * map, mp_obj_t index, mp_map_lookup_kind_t lookup_kind, bool compare_only_ptrs) {
// if the map is an ordered array then we must do a brute force linear search
if (map->is_ordered) {
for (mp_map_elem_t *elem = &map->table[0], *top = &map->table[map->used]; elem < top; elem++) {
Expand Down