aboutsummaryrefslogtreecommitdiff
path: root/xs.h
diff options
context:
space:
mode:
authordefault <nobody@localhost>2025-01-12 06:59:16 +0100
committerdefault <nobody@localhost>2025-01-12 06:59:16 +0100
commit9fd234d05edd9b6690fd9f14546f93b29e8379cf (patch)
treee9c3563f1d3b1fdaa06d1fcfc8ef1d2b8d947cfb /xs.h
parente220270a49bf8689ffb41db489729e77d5996513 (diff)
Backport from xs.
Diffstat (limited to 'xs.h')
-rw-r--r--xs.h16
1 files changed, 12 insertions, 4 deletions
diff --git a/xs.h b/xs.h
index a6e40d5..2a90467 100644
--- 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 */