commit 9fd234d
default
·
2025-01-12 05:59:16 +0000 UTC
parent e220270
Backport from xs.
2 files changed,
+13,
-5
M
xs.h
M
xs.h
+12,
-4
1@@ -1061,14 +1061,15 @@ xs_keyval *xs_keyval_make(xs_keyval *keyval, const xs_str *key, const xs_val *va
2
3 typedef struct {
4 int value_offset; /* offset to value (from dict start) */
5- int next; /* next node in sequential search */
6+ int next; /* next node in sequential scanning */
7 int child[4]; /* child nodes in hashed search */
8 char key[]; /* C string key */
9 } ditem_hdr;
10
11 typedef struct {
12 int size; /* size of full dict (_XS_TYPE_SIZE) */
13- int first; /* first node for sequential search */
14+ int first; /* first node for sequential scanning */
15+ int last; /* last node for sequential scanning */
16 int root; /* root node for hashed search */
17 /* a bunch of ditem_hdr and value follows */
18 } dict_hdr;
19@@ -1153,8 +1154,15 @@ xs_dict *xs_dict_set(xs_dict *dict, const xs_str *key, const xs_val *value)
20 memcpy(dict + di->value_offset, value, vsz);
21
22 /* chain to the sequential list */
23- di->next = dh->first;
24- dh->first = end;
25+ if (dh->first == 0)
26+ dh->first = end;
27+ else {
28+ /* chain this new element to the last one */
29+ ditem_hdr *dil = (ditem_hdr *)(dict + dh->last);
30+ dil->next = end;
31+ }
32+
33+ dh->last = end;
34 }
35 else {
36 /* ditem already exists */
+1,
-1
1@@ -1 +1 @@
2-/* 9e8f5cf300ffbf453031f2ec923cef0822a41b41 2025-01-08T16:57:26+01:00 */
3+/* c317231894f28c39ba45a46f493f124d12a12f3a 2025-01-12T06:56:21+01:00 */