shithub: femtolisp

Download patch

ref: f6115b5ebb70bffd3ba4b11dbe05d96d7e1cc12c
parent: 6fe12400d1d8566e6e8b691676085c4b05559f7e
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Dec 31 13:04:19 EST 2024

fix table relocation

--- a/htable.h
+++ b/htable.h
@@ -3,11 +3,11 @@
 #define HT_N_INLINE 32
 
 typedef struct {
+	void **table;
 	uint32_t size;
 	// this is to skip over non-items in for-each
 	// FIXME(sigrid): in a multithreaded environment this isn't enough
 	uint32_t i;
-	void **table;
 	void *_space[HT_N_INLINE];
 }htable_t;
 
--- a/table.c
+++ b/table.c
@@ -50,13 +50,11 @@
 {
 	htable_t *oldh = cvalue_data(oldv);
 	htable_t *h = cvalue_data(newv);
-	if(oldh->table == &oldh->_space[0])
-		h->table = &h->_space[0];
-	size_t i;
+	h->table = oldh->table == &oldh->_space[0] ? &h->_space[0] : oldh->table;
 	h->i = oldh->i;
-	for(i = 0; i < h->size; i++){
-		if(h->table[i] != HT_NOTFOUND)
-			h->table[i] = (void*)relocate((value_t)h->table[i]);
+	for(size_t i = 0; i < h->size; i++){
+		if(oldh->table[i] != HT_NOTFOUND)
+			h->table[i] = (void*)relocate((value_t)oldh->table[i]);
 	}
 }