MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

improve hash opt

+27 -23
+1
include/internal.h
··· 57 57 #define JS_V_PROMISE 12 58 58 #define JS_V_BIGINT 14 59 59 #define JS_V_GENERATOR 17 60 + #define JS_HASH_SIZE 512 60 61 61 62 #define NANBOX_PREFIX 0x7FC0000000000000ULL 62 63 #define NANBOX_PREFIX_CHK 0x3FEULL
+1 -1
meson.build
··· 86 86 build_date = run_command('date', '+%Y-%m-%d', check: true).stdout().strip() 87 87 88 88 version_conf = configuration_data() 89 - version_conf.set('ANT_VERSION', '0.3.1.14') 89 + version_conf.set('ANT_VERSION', '0.3.1.15') 90 90 version_conf.set('ANT_GIT_HASH', git_hash) 91 91 version_conf.set('ANT_BUILD_DATE', build_date) 92 92
+25 -22
src/gc.c
··· 9 9 #define MCO_API extern 10 10 #include "minicoro.h" 11 11 12 - typedef struct { 12 + typedef struct gc_forward_node { 13 13 jsoff_t old_off; 14 14 jsoff_t new_off; 15 - } gc_forward_t; 15 + struct gc_forward_node *next; 16 + } gc_forward_node_t; 16 17 17 18 typedef struct { 18 - gc_forward_t *entries; 19 - size_t count; 20 - size_t capacity; 19 + gc_forward_node_t *buckets[JS_HASH_SIZE]; 21 20 } gc_forward_table_t; 22 21 23 22 typedef struct { ··· 37 36 ctx->mark_bits[idx >> 3] |= (1 << (idx & 7)); 38 37 } 39 38 39 + static inline size_t fwd_hash(jsoff_t off) { 40 + return (off >> 2) & (JS_HASH_SIZE - 1); 41 + } 42 + 40 43 static void fwd_init(gc_forward_table_t *fwd) { 41 - fwd->capacity = 256; 42 - fwd->entries = (gc_forward_t *)malloc(fwd->capacity * sizeof(gc_forward_t)); 43 - fwd->count = 0; 44 + memset(fwd->buckets, 0, sizeof(fwd->buckets)); 44 45 } 45 46 46 47 static void fwd_add(gc_forward_table_t *fwd, jsoff_t old_off, jsoff_t new_off) { 47 - if (fwd->count >= fwd->capacity) { 48 - fwd->capacity *= 2; 49 - fwd->entries = (gc_forward_t *)realloc(fwd->entries, fwd->capacity * sizeof(gc_forward_t)); 50 - } 51 - fwd->entries[fwd->count].old_off = old_off; 52 - fwd->entries[fwd->count].new_off = new_off; 53 - fwd->count++; 48 + size_t h = fwd_hash(old_off); 49 + gc_forward_node_t *node = malloc(sizeof(gc_forward_node_t)); 50 + node->old_off = old_off; 51 + node->new_off = new_off; 52 + node->next = fwd->buckets[h]; 53 + fwd->buckets[h] = node; 54 54 } 55 55 56 56 static jsoff_t fwd_lookup(gc_forward_table_t *fwd, jsoff_t old_off) { 57 - // linear search, could be optimized with hash table for large heaps 58 - for (size_t i = 0; i < fwd->count; i++) { 59 - if (fwd->entries[i].old_off == old_off) return fwd->entries[i].new_off; 57 + size_t h = fwd_hash(old_off); 58 + for (gc_forward_node_t *n = fwd->buckets[h]; n; n = n->next) { 59 + if (n->old_off == old_off) return n->new_off; 60 60 } 61 61 return (jsoff_t)~0; 62 62 } 63 63 64 64 static void fwd_free(gc_forward_table_t *fwd) { 65 - free(fwd->entries); 66 - fwd->entries = NULL; 67 - fwd->count = 0; 68 - fwd->capacity = 0; 65 + for (size_t i = 0; i < JS_HASH_SIZE; i++) { 66 + gc_forward_node_t *n = fwd->buckets[i]; 67 + while (n) { 68 + gc_forward_node_t *next = n->next; 69 + free(n); n = next; 70 + } 71 + } 69 72 } 70 73 71 74 static inline jsoff_t gc_loadoff(uint8_t *mem, jsoff_t off) {