Browse Source

Backport from xs.

default 3 months ago
parent
commit
9fd234d05e
2 changed files with 13 additions and 5 deletions
  1. 12 4
      xs.h
  2. 1 1
      xs_version.h

+ 12 - 4
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 */

+ 1 - 1
xs_version.h

@@ -1 +1 @@
-/* 9e8f5cf300ffbf453031f2ec923cef0822a41b41 2025-01-08T16:57:26+01:00 */
+/* c317231894f28c39ba45a46f493f124d12a12f3a 2025-01-12T06:56:21+01:00 */