mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
py: Fix dict.copy() and low-level map/set allocation.
Two things: 1) set flags in copy properly; make mp_map_init() not be too smart and do something with requested alloc size. Policy of using prime numbers for alloc size is high-level policy which should be applied at corresponding high levels. Low-level functions should just do what they're asked to, because they don't have enough context to be smarter than that. For example, munging with alloc size of course breaks dict copying (as changing sizes requires rehashing).
This commit is contained in:
4
py/map.c
4
py/map.c
@@ -30,7 +30,7 @@ void mp_map_init(mp_map_t *map, int n) {
|
||||
map->alloc = 0;
|
||||
map->table = NULL;
|
||||
} else {
|
||||
map->alloc = get_doubling_prime_greater_or_equal_to(n + 1);
|
||||
map->alloc = n;
|
||||
map->table = m_new0(mp_map_elem_t, map->alloc);
|
||||
}
|
||||
map->used = 0;
|
||||
@@ -197,7 +197,7 @@ mp_map_elem_t* mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t
|
||||
/* set */
|
||||
|
||||
void mp_set_init(mp_set_t *set, int n) {
|
||||
set->alloc = get_doubling_prime_greater_or_equal_to(n + 1);
|
||||
set->alloc = n;
|
||||
set->used = 0;
|
||||
set->table = m_new0(mp_obj_t, set->alloc);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user