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.

prevent string allocation on init

+29 -24
+8 -3
include/internal.h
··· 5 5 #include "object.h" 6 6 #include "pool.h" 7 7 #include "sugar.h" 8 + #include "errors.h" 8 9 #include "arena.h" 9 10 #include "descriptors.h" 10 11 #include "esm/loader.h" ··· 440 441 } 441 442 442 443 static inline ant_value_t defmethod(ant_t *js, ant_value_t obj, const char *name, size_t len, ant_value_t fn) { 443 - ant_value_t k = js_mkstr(js, name, len); 444 - if (is_err(k)) return k; 445 - return mkprop(js, obj, k, fn, ANT_PROP_ATTR_WRITABLE | ANT_PROP_ATTR_CONFIGURABLE); 444 + const char *interned = intern_string(name, len); 445 + if (!interned) return js_mkerr(js, "oom"); 446 + 447 + return mkprop_interned( 448 + js, obj, interned, fn, 449 + ANT_PROP_ATTR_WRITABLE | ANT_PROP_ATTR_CONFIGURABLE 450 + ); 446 451 } 447 452 448 453 static inline ant_flat_string_t *str_flat_from_bytes(const char *str) {
+20 -20
src/ant.c
··· 2543 2543 } 2544 2544 2545 2545 ant_value_t js_mkprop_fast(ant_t *js, ant_value_t obj, const char *key, size_t len, ant_value_t v) { 2546 - ant_value_t k = js_mkstr(js, key, len); 2547 - if (is_err(k)) return k; 2548 - return mkprop(js, obj, k, v, 0); 2546 + const char *interned = intern_string(key, len); 2547 + if (!interned) return js_mkerr(js, "oom"); 2548 + return mkprop_interned(js, obj, interned, v, 0); 2549 2549 } 2550 2550 2551 2551 ant_offset_t js_mkprop_fast_off(ant_t *js, ant_value_t obj, const char *key, size_t len, ant_value_t v) { 2552 - ant_value_t k = js_mkstr(js, key, len); 2553 - if (is_err(k)) return 0; 2554 - ant_value_t prop = mkprop(js, obj, k, v, 0); 2552 + const char *interned = intern_string(key, len); 2553 + if (!interned) return 0; 2554 + ant_value_t prop = mkprop_interned(js, obj, interned, v, 0); 2555 2555 if (is_err(prop)) return 0; 2556 - return lkp(js, obj, key, len); 2556 + return lkp_interned(js, obj, interned, len); 2557 2557 } 2558 2558 2559 2559 void js_saveval(ant_t *js, ant_offset_t off, ant_value_t v) { ··· 3390 3390 3391 3391 ant_value_t setprop_cstr(ant_t *js, ant_value_t obj, const char *key, size_t len, ant_value_t v) { 3392 3392 obj = js_as_obj(obj); 3393 - ant_value_t k = js_mkstr(js, key, len); 3394 - if (is_err(k)) return k; 3395 - return mkprop(js, obj, k, v, 0); 3393 + const char *interned = intern_string(key, len); 3394 + if (!interned) return js_mkerr(js, "oom"); 3395 + return mkprop_interned(js, obj, interned, v, 0); 3396 3396 } 3397 3397 3398 3398 ant_value_t js_define_own_prop(ant_t *js, ant_value_t obj, const char *key, size_t klen, ant_value_t v) { ··· 11693 11693 static void js_set_import_meta_prop(ant_t *js, ant_value_t import_meta) { 11694 11694 ant_value_t import_fn = js_get_import_func(js); 11695 11695 if (vtype(import_fn) != T_FUNC) return; 11696 - js_setprop(js, js_func_obj(import_fn), js_mkstr(js, "meta", 4), import_meta); 11696 + setprop_cstr(js, js_func_obj(import_fn), "meta", 4, import_meta); 11697 11697 } 11698 11698 11699 11699 static void js_set_import_module_ctx(ant_t *js, ant_value_t module_ctx) { ··· 11744 11744 if ((is_builtin && last_slash) || (!is_builtin && last_slash && scheme_end && last_slash > scheme_end + 2)) { 11745 11745 *last_slash = '\0'; 11746 11746 ant_value_t dirname_val = js_mkstr(js, filename_copy, strlen(filename_copy)); 11747 - if (!is_err(dirname_val)) js_setprop(js, import_meta, js_mkstr(js, "dirname", 7), dirname_val); 11747 + if (!is_err(dirname_val)) setprop_cstr(js, import_meta, "dirname", 7, dirname_val); 11748 11748 } 11749 11749 11750 11750 free(filename_copy); ··· 11761 11761 char *dir = dirname(filename_copy); 11762 11762 if (dir) { 11763 11763 ant_value_t dirname_val = js_mkstr(js, dir, strlen(dir)); 11764 - if (!is_err(dirname_val)) js_setprop(js, import_meta, js_mkstr(js, "dirname", 7), dirname_val); 11764 + if (!is_err(dirname_val)) setprop_cstr(js, import_meta, "dirname", 7, dirname_val); 11765 11765 } 11766 11766 11767 11767 free(filename_copy); ··· 11786 11786 ant_value_t url_val = (is_url || is_builtin) 11787 11787 ? js_mkstr(js, filename, strlen(filename)) 11788 11788 : js_esm_make_file_url(js, filename); 11789 - if (!is_err(url_val)) js_setprop(js, import_meta, js_mkstr(js, "url", 3), url_val); 11789 + if (!is_err(url_val)) setprop_cstr(js, import_meta, "url", 3, url_val); 11790 11790 11791 11791 ant_value_t filename_val = js_get(js, module_ctx, "filename"); 11792 11792 if (vtype(filename_val) == T_STR) 11793 - js_setprop(js, import_meta, js_mkstr(js, "filename", 8), filename_val); 11793 + setprop_cstr(js, import_meta, "filename", 8, filename_val); 11794 11794 11795 11795 if (is_url || is_builtin) js_set_import_meta_special_dirname(js, import_meta, filename, is_builtin); 11796 11796 else js_set_import_meta_path_dirname(js, import_meta, filename); 11797 11797 11798 - js_setprop(js, import_meta, js_mkstr(js, "main", 4), is_main ? js_true : js_false); 11798 + setprop_cstr(js, import_meta, "main", 4, is_main ? js_true : js_false); 11799 11799 11800 11800 ant_value_t resolve_fn = js_heavy_mkfun(js, builtin_import_meta_resolve, js_mkundef()); 11801 11801 if (vtype(resolve_fn) == T_FUNC) 11802 11802 js_set_slot_wb(js, js_func_obj(resolve_fn), SLOT_MODULE_CTX, module_ctx); 11803 - js_setprop(js, import_meta, js_mkstr(js, "resolve", 7), resolve_fn); 11803 + setprop_cstr(js, import_meta, "resolve", 7, resolve_fn); 11804 11804 11805 11805 return import_meta; 11806 11806 } ··· 11825 11825 return filename_val; 11826 11826 } 11827 11827 GC_ROOT_PIN(js, filename_val); 11828 - js_setprop(js, module_ctx, js_mkstr(js, "filename", 8), filename_val); 11828 + setprop_cstr(js, module_ctx, "filename", 8, filename_val); 11829 11829 11830 11830 ant_value_t import_meta = js_create_import_meta_for_context(js, module_ctx, filename, is_main); 11831 11831 if (is_err(import_meta)) { ··· 11833 11833 return import_meta; 11834 11834 } 11835 11835 GC_ROOT_PIN(js, import_meta); 11836 - js_setprop(js, module_ctx, js_mkstr(js, "meta", 4), import_meta); 11836 + setprop_cstr(js, module_ctx, "meta", 4, import_meta); 11837 11837 11838 11838 GC_ROOT_RESTORE(js, root_mark); 11839 11839 return module_ctx; ··· 11873 11873 if (is_object_type(function_proto)) js_set_proto_wb(js, import_obj, function_proto); 11874 11874 set_slot(import_obj, SLOT_CFUNC, js_mkfun(builtin_import)); 11875 11875 js_set_slot_wb(js, import_obj, SLOT_MODULE_CTX, module_ctx); 11876 - js_setprop(js, import_obj, js_mkstr(js, "meta", 4), import_meta); 11876 + setprop_cstr(js, import_obj, "meta", 4, import_meta); 11877 11877 11878 11878 ant_value_t import_fn = js_obj_to_func(import_obj); 11879 11879 GC_ROOT_RESTORE(js, root_mark);
+1 -1
src/gc/gc.c
··· 88 88 gc_ropes_sweep(js); 89 89 90 90 js->gc_last_live = js->obj_arena.live_count; 91 - js->old_live_count = js->obj_arena.live_count; /* after major GC all live = old */ 91 + js->old_live_count = js->obj_arena.live_count; 92 92 js->minor_gc_count = 0; 93 93 94 94 ant_pool_stats_t pool_stats = js_class_pool_stats(&js->pool.string);