From 607f0d271211e37d96ce7ba50a3f69372c000779 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 20 Aug 2019 20:07:57 -0700 Subject: lib: streamline interning slightly. We get rid of some defaulting and error checks from interning. This saves a few cycles on startup in the large number of intern calls that are performed. * eval.c (eval_init): Wire the intern intrinsic to the new intern_intrinsic function rather than intern. * lib.c (intern): Remove package lookup and error check on str argument. (intern_intrinsic): New function, which has the package lookup and error check. (intern_fallback): Remove package lookup and error check. * lib.h (intern_intrinsic): Declared. * txr.c (txr_main): Fix one instance of an intern call that relies on defaulting of the second argument, by passing cur_package. --- lib.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'lib.c') diff --git a/lib.c b/lib.c index e2683245..9d40f21c 100644 --- a/lib.c +++ b/lib.c @@ -5393,17 +5393,11 @@ val find_symbol_fb(val name, val package_in, val notfound_val_in) return default_null_arg(notfound_val_in); } -val intern(val str, val package_in) +val intern(val str, val package) { val self = lit("intern"); val new_p; - loc place; - val package = get_package(self, package_in, t); - - if (!stringp(str)) - uw_throwf(error_s, lit("~a: name ~s isn't a string"), self, str, nao); - - place = gethash_l(self, package->pk.symhash, str, mkcloc(new_p)); + loc place = gethash_l(self, package->pk.symhash, str, mkcloc(new_p)); if (!new_p) { return deref(place); @@ -5414,6 +5408,17 @@ val intern(val str, val package_in) } } +val intern_intrinsic(val str, val package_in) +{ + val self = lit("intern"); + val package = get_package(self, package_in, t); + + if (!stringp(str)) + uw_throwf(error_s, lit("~a: name ~s isn't a string"), self, str, nao); + + return intern(str, package); +} + val unintern(val symbol, val package_in) { val self = lit("unintern"); @@ -5492,15 +5497,11 @@ val set_package_fallback_list(val package_in, val list_in) return set_hash_userdata(package->pk.symhash, list); } -val intern_fallback(val str, val package_in) +val intern_fallback(val str, val package) { val self = lit("intern-fallback"); - val package = get_package(self, package_in, nil); val fblist = get_hash_userdata(package->pk.symhash); - if (!stringp(str)) - uw_throwf(error_s, lit("~a: name ~s isn't a string"), self, str, nao); - if (fblist) { val found = gethash_e(self, package->pk.symhash, str); -- cgit v1.2.3