Skip to content

Commit 136cb7f

Browse files
committed
py/map: Don't include ordered-dict mutating code when not needed.
1 parent f5fb68e commit 136cb7f

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎py/map.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t
170170
if (map->is_ordered) {
171171
for (mp_map_elem_t *elem = &map->table[0], *top = &map->table[map->used]; elem < top; elem++) {
172172
if (elem->key == index || (!compare_only_ptrs && mp_obj_equal(elem->key, index))) {
173+
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
173174
if (MP_UNLIKELY(lookup_kind == MP_MAP_LOOKUP_REMOVE_IF_FOUND)) {
174175
// remove the found element by moving the rest of the array down
175176
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
180181
elem->key = MP_OBJ_NULL;
181182
elem->value = value;
182183
}
184+
#endif
183185
return elem;
184186
}
185187
}
188+
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
186189
if (MP_LIKELY(lookup_kind != MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)) {
187190
return NULL;
188191
}
@@ -198,6 +201,9 @@ mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t
198201
map->all_keys_are_qstrs = 0;
199202
}
200203
return elem;
204+
#else
205+
return NULL;
206+
#endif
201207
}
202208

203209
// map is a hash table (not an ordered array), so do a hash lookup

0 commit comments

Comments
 (0)