aboutsummaryrefslogtreecommitdiffstats
path: root/core/module-list.c
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-10-19 07:59:15 +0100
committereunhhu <[email protected]>2026-10-19 07:59:15 +0100
commit1c1133ce8258dad367aad3b7c8eee0083aecf772 (patch)
treec939ae2e9ba6a2a220f1633fef107f9514ebb55b /core/module-list.c
parentf1bb9de4ac72136a1b0722ce77ac4ea6fd4fa413 (diff)
downloadpure-1c1133ce8258dad367aad3b7c8eee0083aecf772.tar.gz
pure-1c1133ce8258dad367aad3b7c8eee0083aecf772.zip
A list value of numbers copied whole (140's LIST_VALUE review, no new opcode, no change to what a module means): nest() made every list value item by item into a new tree (64 ns an item, 250 ns a copy fixed); an event's list in FLAT arrays, not keyed, its cells numbers, bools and integers, is now copied column by column (pure_list_copied: 600 items 38,268 to 985 ns, 60 items 3,926 to 324); UAX #14's nine lists a line 6,917 to 6,445 ns a code point (-6.8%, the same instructions); JSON tree's, HTTP's and inflate's (trees: texts or lists in their records, or few) as they were; copied_lists in test-module (random lists against item by item, then each changed apart; trees, keys and texts not copied so)
Diffstat (limited to 'core/module-list.c')
-rw-r--r--core/module-list.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/core/module-list.c b/core/module-list.c
index 2f2c359..91dd378 100644
--- a/core/module-list.c
+++ b/core/module-list.c
@@ -1800,6 +1800,30 @@ bool pure_list_arrays(PureList *list) {
unsigned pure_list_form(const PureList *list) { return list->form; }
+PureList *pure_list_copied(const PureList *from) {
+ const Layout *l = &from->layout;
+ if (from->form != FLAT || !from->arrays || from->pack || from->copy || l->key >= 0) return NULL;
+ for (unsigned f = 0; f < l->fields; ++f)
+ if (pure_cell_text(l->kinds[f]) || l->kinds[f] == PURE_CELL_LIST) return NULL;
+ PureList *list = pure_list_new(l->fields, l->kinds);
+ if (!list || !pure_list_arrays(list)) {
+ pure_list_free(list);
+ return NULL;
+ }
+ for (unsigned f = 0; f < l->fields; ++f) { /* its widths as they are: narrowed or widened by what it holds */
+ list->width[f] = from->width[f];
+ if (!from->count || !from->width[f]) continue;
+ if (!(list->columns[f] = malloc(from->count * from->width[f]))) {
+ pure_list_free(list);
+ return NULL;
+ }
+ memcpy(list->columns[f], from->columns[f], from->count * from->width[f]);
+ }
+ list->count = list->room = from->count;
+ list->bytes = from->bytes;
+ return list;
+}
+
bool pure_list_cells(PureList *list, PureCells *out) {
if (list->form != FLAT && !(list->form == DENSE && pure_list_full(list))) return false;
const Layout *l = &list->layout;