summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-04-06 21:00:58 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-04-06 21:31:42 +0300
commit5fedd0c3b708d2874f93897ff5de2d533079c1fc (patch)
tree8aa5a3cd900ea63431e7cd626268513885adacf3
parentea85a121f2b4bb806fbb59cd5da3f94cae8fb57c (diff)
downloadmicropython-5fedd0c3b708d2874f93897ff5de2d533079c1fc.tar.gz
micropython-5fedd0c3b708d2874f93897ff5de2d533079c1fc.zip
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).
-rw-r--r--py/map.c4
-rw-r--r--py/objdict.c2
2 files changed, 4 insertions, 2 deletions
diff --git a/py/map.c b/py/map.c
index bb3d5d8898..dadaa22a92 100644
--- a/py/map.c
+++ b/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);
}
diff --git a/py/objdict.c b/py/objdict.c
index 7aadeefab5..3855c36e6a 100644
--- a/py/objdict.c
+++ b/py/objdict.c
@@ -164,6 +164,8 @@ STATIC mp_obj_t dict_copy(mp_obj_t self_in) {
mp_obj_dict_t *self = self_in;
mp_obj_dict_t *other = mp_obj_new_dict(self->map.alloc);
other->map.used = self->map.used;
+ other->map.all_keys_are_qstrs = self->map.all_keys_are_qstrs;
+ other->map.table_is_fixed_array = 0;
memcpy(other->map.table, self->map.table, self->map.alloc * sizeof(mp_map_elem_t));
return other;
}