summaryrefslogtreecommitdiffstats
path: root/cadr.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2022-02-19 08:27:20 -0800
committerKaz Kylheku <kaz@kylheku.com>2022-02-19 08:27:20 -0800
commit834ebaf314521b9b61a2e9f0f3f3afa8b16990bb (patch)
treece5fdc70b2b4826d105426a4baabfac8027e851b /cadr.c
parente66c35b6eebe6f04c8feca78c2a3e68205f9dc56 (diff)
downloadtxr-834ebaf314521b9b61a2e9f0f3f3afa8b16990bb.tar.gz
txr-834ebaf314521b9b61a2e9f0f3f3afa8b16990bb.tar.bz2
txr-834ebaf314521b9b61a2e9f0f3f3afa8b16990bb.zip
autoload: use weak hash to erase registrations.
In autoload the _set_entries functions are being called twice: the first time with a functional argument to associate symbols with that function, and then when the module is loaded, a second time with a nil argument to erase those associations. This is inefficient; some modules have many symbols to remove from a hash. What we can do is make the hash weak; associate the symbols with a function weakly, such that those entries lapse when the function becomes garbage. Lapsing of weak hash table entries during GC is more efficient than making numerous calls to remhash. We can use a separate strong hash table to hang on to the functions; when a module is instantiated, all we have to do is remove the instantiation function from the table. Then that function is reachable only as a weak value from the other tables. * autoload.c (autoload_reg_hash): New static variable. (place_instantiate, ver_instantiate, ifa_instantiate, txr_case_instantiate, with_resources_instantiate, path_test_instantiate, struct_instantiate, with_stream_instantiate, hash_instantiate, except_instantiate, type_instantiate, yield_instantiate, sock_instantiate, termios_instantiate, awk_instantiate, build_instantiate, trace_instantiate, getopts_instantiate, package_instantiate, getput_instantiate, tagbody_instantiate, pmac_instantiate, error_instantiate, keyparams_instantiate, ffi_instantiate, doloop_instantiate, stream_wrap_instantiate, asm_instantiate, compiler_instantiate, debugger_instantiate, op_instantiate, save_exe_instantiate, defset_instantiate, copy_file_instantiate, arith_each_instantiate, each_prod_instantiate, quips_instantiate, match_instantiate, doc_instantiate, pic_instantiate, constfun_instantiate): Remove set_fun argument and call to that function. (autoload_reg): Remove argument from instantiate function. Add the function to the autoload_reg_hash table, associated with the t symbol. (autoload_init_tables): Initialize autoload_reg_hash. Turn the existing symbol hashes into weak tables. Let's use weak or-semantics, so they don't hang onto uninterned symbols. (autoload_try): If a symbol resolves to a function, indicating a load might be required, we now must verify whether that is really the case by seeing whether the function exists in the autolod_reg_hash table. If so, we remove it from that table and do the load. * autoload.h (autoload_reg): Declaration updated. * gencadr.txr (cadr_register): Remove set_fun argument and call to that function. * cadr.c: Regenerated.
Diffstat (limited to 'cadr.c')
-rw-r--r--cadr.c3
1 files changed, 1 insertions, 2 deletions
diff --git a/cadr.c b/cadr.c
index 2a2ce117..97d128ec 100644
--- a/cadr.c
+++ b/cadr.c
@@ -340,9 +340,8 @@ val cdddddr(val cons)
return cdr(cdr(cdr(cdr(cdr(cons)))));
}
-static val cadr_register(val set_fun)
+static val cadr_register(void)
{
- funcall1(set_fun, nil);
reg_fun(intern(lit("caar"), user_package), func_n1(caar));
reg_fun(intern(lit("cadr"), user_package), func_n1(cadr));
reg_fun(intern(lit("cdar"), user_package), func_n1(cdar));