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.

optimize argument handling

+41 -18
+11
examples/demo/tco_fib.js
··· 1 + function fib(n) { 2 + if (n < 2) return n; 3 + return fib(n - 1) + fib(n - 2); 4 + } 5 + 6 + const start = performance.now(); 7 + const result = fib(30); 8 + const end = performance.now(); 9 + 10 + console.log(`fibonacci(30) = ${result}`); 11 + console.log(`Time: ${(end - start).toFixed(2)} ms`);
+1 -1
libant/scripts/header.sh
··· 111 111 continue 112 112 fi 113 113 114 - if [[ "$line" =~ ^[[:space:]]*#[[:space:]]*include[[:space:]]+\<(config|common|argtable3|types|utarray|uthash|minicoro)\.h\> ]]; then 114 + if [[ "$line" =~ ^[[:space:]]*#[[:space:]]*include[[:space:]]+\<(config|common|uv|argtable3|types|utarray|uthash|minicoro)\.h\> ]]; then 115 115 continue 116 116 fi 117 117
+1
meson/ant.version
··· 1 + 0.5.3
+28 -17
src/ant.c
··· 6859 6859 jsoff_t caller_clen = js->clen; 6860 6860 jsoff_t caller_pos = js->pos; 6861 6861 6862 - UT_array *args_arr; 6863 - utarray_new(args_arr, &jsval_icd); 6862 + jsval_t args_buf[8]; 6863 + jsval_t *args = args_buf; 6864 6864 6865 - for (int i = 0; i < bound_argc; i++) { utarray_push_back(args_arr, &bound_args[i]); } 6865 + int argc = 0; int args_cap = 8; 6866 + bool args_on_heap = false; 6867 + 6868 + #define ARGS_PUSH(val) do { \ 6869 + if (argc >= args_cap) { \ 6870 + int _new_cap = args_cap * 2; \ 6871 + jsval_t *_new = malloc(_new_cap * sizeof(jsval_t)); \ 6872 + memcpy(_new, args, argc * sizeof(jsval_t)); \ 6873 + if (args_on_heap) free(args); \ 6874 + args = _new; \ 6875 + args_cap = _new_cap; \ 6876 + args_on_heap = true; \ 6877 + } \ 6878 + args[argc++] = (val); \ 6879 + } while (0) 6880 + 6881 + for (int i = 0; i < bound_argc; i++) ARGS_PUSH(bound_args[i]); 6866 6882 caller_pos = skiptonext(caller_code, caller_clen, caller_pos, NULL); 6867 - 6883 + 6868 6884 while (caller_pos < caller_clen && caller_code[caller_pos] != ')') { 6869 6885 bool is_spread = ( 6870 6886 caller_code[caller_pos] == '.' && caller_pos + 2 < caller_clen && ··· 6877 6893 caller_pos = js->pos; 6878 6894 if (is_spread && vtype(arg) == T_ARR) { 6879 6895 jsoff_t len = js_arr_len(js, arg); 6880 - for (jsoff_t i = 0; i < len; i++) { 6881 - jsval_t elem = js_arr_get(js, arg, i); 6882 - utarray_push_back(args_arr, &elem); 6883 - } 6884 - } else { 6885 - utarray_push_back(args_arr, &arg); 6886 - } 6896 + for (jsoff_t i = 0; i < len; i++) ARGS_PUSH(js_arr_get(js, arg, i)); 6897 + } else ARGS_PUSH(arg); 6887 6898 caller_pos = skiptonext(caller_code, caller_clen, caller_pos, NULL); 6888 6899 if (caller_pos < caller_clen && caller_code[caller_pos] == ',') caller_pos++; 6889 6900 caller_pos = skiptonext(caller_code, caller_clen, caller_pos, NULL); 6890 6901 } 6891 - js->pos = caller_pos; 6892 6902 6893 - jsval_t *args = (jsval_t *)utarray_front(args_arr); 6894 - int argc = (int)utarray_len(args_arr); 6903 + #undef ARGS_PUSH 6904 + 6905 + js->pos = caller_pos; 6895 6906 js->scope = function_scope; 6896 6907 6897 6908 parsed_func_t *pf = get_or_parse_func(fn, fnlen); 6898 6909 if (!pf) { 6899 - utarray_free(args_arr); 6910 + if (args_on_heap) free(args); 6900 6911 restore_saved_scope(js); 6901 6912 if (global_scope_stack && utarray_len(global_scope_stack) > 0) utarray_pop_back(global_scope_stack); 6902 6913 return js_mkerr(js, "failed to parse function"); ··· 6913 6924 } 6914 6925 jsval_t r = bind_destruct_pattern(js, &fn[pp->pattern_off], pp->pattern_len, arg_val, function_scope); 6915 6926 if (is_err(r)) { 6916 - utarray_free(args_arr); 6927 + if (args_on_heap) free(args); 6917 6928 restore_saved_scope(js); 6918 6929 if (global_scope_stack && utarray_len(global_scope_stack) > 0) utarray_pop_back(global_scope_stack); 6919 6930 return r; ··· 7009 7020 js->skip_func_hoist = false; 7010 7021 if (global_scope_stack && utarray_len(global_scope_stack) > 0) utarray_pop_back(global_scope_stack); 7011 7022 7012 - utarray_free(args_arr); 7023 + if (args_on_heap) free(args); 7013 7024 restore_saved_scope(js); 7014 7025 7015 7026 return res;