diff options
Diffstat (limited to 'core')
| -rw-r--r-- | core/module-list.c | 3 | ||||
| -rw-r--r-- | core/test-module.c | 18 |
2 files changed, 20 insertions, 1 deletions
diff --git a/core/module-list.c b/core/module-list.c index 0d53c60..3b9ca38 100644 --- a/core/module-list.c +++ b/core/module-list.c @@ -1147,7 +1147,8 @@ bool pure_list_lookup(const PureList *list, unsigned key_field, PureCell key, un size_t pure_list_count(const PureList *list) { return list->count; } PureList *pure_list_share(PureList *list, PureRetired *retired, uint64_t epoch) { - if (!make_tree(list)) return NULL; /* a copy reads a tree */ + /* A copy reads a tree; an empty list (an event's, between events) stays as it is. */ + if (list->count && !make_tree(list)) return NULL; PureList *copy = malloc(sizeof(*copy)); if (!copy) return NULL; *copy = (PureList){.layout = list->layout, .root = list->root, .count = list->count, .bytes = list->bytes, diff --git a/core/test-module.c b/core/test-module.c index f76c871..a509349 100644 --- a/core/test-module.c +++ b/core/test-module.c @@ -1483,6 +1483,24 @@ static void arrays_equivalence(void) { pure_list_free(t); } CHECK(forms[0] > 10000 && forms[1] > 10000 && forms[2] > 10000 && conversions > 100); + /* A snapshot shares every list: an event's, empty between events, stays in arrays; one with items is a tree for its copy. */ + { + PureList *list = pure_list_new(2, fields); + PureRetired retired = {0}; + CHECK(list && pure_list_arrays(list)); + PureList *copy = pure_list_share(list, &retired, 1); + CHECK(copy && pure_list_count(copy) == 0 && pure_list_form(list) == 1); + pure_list_free(copy); + for (unsigned i = 0; i < 100; ++i) + CHECK(pure_list_insert(list, i, (PureCell[]){{.num = i}, {.size = 0}}, NULL) == PURE_OK); + CHECK((copy = pure_list_share(list, &retired, 2)) && pure_list_form(list) == 0 && pure_list_count(copy) == 100); + CHECK(pure_list_get(copy, 99, 0).num == 99); + pure_list_free(copy); + pure_list_clear(list); + CHECK(pure_list_form(list) == 1); /* arrays again, the next event */ + pure_list_free(list); + pure_retired_free(&retired); + } printf("{\"arrays\":{\"steps\":%zu,\"tree\":%zu,\"flat\":%zu,\"dense\":%zu,\"conversions\":%zu}}\n", steps, forms[0], forms[1], forms[2], conversions); } |
