Skip to content

Commit

Permalink
py/map: Store key/value in earliest possible slot in hash table.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dpgeorge committed Nov 19, 2015
1 parent db0a5ae commit 593faf1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions py/map.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,12 @@ mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t
if (avail_slot == NULL) {
avail_slot = slot;
}
slot->key = index;
slot->value = MP_OBJ_NULL;
avail_slot->key = index;
avail_slot->value = MP_OBJ_NULL;
if (!MP_OBJ_IS_QSTR(index)) {
map->all_keys_are_qstrs = 0;
}
return slot;
return avail_slot;
} else {
return NULL;
}
Expand Down

0 comments on commit 593faf1

Please sign in to comment.