Skip to content

Commit 593faf1

Browse files
committed
py/map: Store key/value in earliest possible slot in hash table.
This change makes the code behave how it was supposed to work when first written. The avail_slot variable is set to the first free slot when looking for a key (which would come from deleting an entry). So it's more efficient (for subsequent lookups) to insert a new key into such a slot, rather than the very last slot that was searched.
1 parent db0a5ae commit 593faf1

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

py/map.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,12 @@ mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t
214214
if (avail_slot == NULL) {
215215
avail_slot = slot;
216216
}
217-
slot->key = index;
218-
slot->value = MP_OBJ_NULL;
217+
avail_slot->key = index;
218+
avail_slot->value = MP_OBJ_NULL;
219219
if (!MP_OBJ_IS_QSTR(index)) {
220220
map->all_keys_are_qstrs = 0;
221221
}
222-
return slot;
222+
return avail_slot;
223223
} else {
224224
return NULL;
225225
}

0 commit comments

Comments
 (0)