commit 9fd234d05edd9b6690fd9f14546f93b29e8379cf
parent e220270a49bf8689ffb41db489729e77d5996513
Author: default <nobody@localhost>
Date: Sun, 12 Jan 2025 06:59:16 +0100
Backport from xs.
Diffstat:
2 files changed, 13 insertions(+), 5 deletions(-)
diff --git a/xs.h b/xs.h
@@ -1061,14 +1061,15 @@ xs_keyval *xs_keyval_make(xs_keyval *keyval, const xs_str *key, const xs_val *va
typedef struct {
int value_offset; /* offset to value (from dict start) */
- int next; /* next node in sequential search */
+ int next; /* next node in sequential scanning */
int child[4]; /* child nodes in hashed search */
char key[]; /* C string key */
} ditem_hdr;
typedef struct {
int size; /* size of full dict (_XS_TYPE_SIZE) */
- int first; /* first node for sequential search */
+ int first; /* first node for sequential scanning */
+ int last; /* last node for sequential scanning */
int root; /* root node for hashed search */
/* a bunch of ditem_hdr and value follows */
} dict_hdr;
@@ -1153,8 +1154,15 @@ xs_dict *xs_dict_set(xs_dict *dict, const xs_str *key, const xs_val *value)
memcpy(dict + di->value_offset, value, vsz);
/* chain to the sequential list */
- di->next = dh->first;
- dh->first = end;
+ if (dh->first == 0)
+ dh->first = end;
+ else {
+ /* chain this new element to the last one */
+ ditem_hdr *dil = (ditem_hdr *)(dict + dh->last);
+ dil->next = end;
+ }
+
+ dh->last = end;
}
else {
/* ditem already exists */
diff --git a/xs_version.h b/xs_version.h
@@ -1 +1 @@
-/* 9e8f5cf300ffbf453031f2ec923cef0822a41b41 2025-01-08T16:57:26+01:00 */
+/* c317231894f28c39ba45a46f493f124d12a12f3a 2025-01-12T06:56:21+01:00 */