summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2012-02-19 14:25:29 +0100
committerAndy Wingo <wingo@pobox.com>2012-02-19 20:52:25 +0100
commit5077c02d7420ce03c4d4566b6ab04ceb9cf150ac (patch)
treef216b4270720eab07bbf409a7ace983a1d0a70aa
parent36931b31b5e90e4135d57e864d9a617481678c67 (diff)
downloadguile-wip-finalizers.tar.gz
avoid allocating finalizer data for symbols in weak setswip-finalizers
* libguile/weak-set.c (symbol_finalizer, register_finalizer): Add a fast path for symbols, to avoid allocating the finalizer data.
-rw-r--r--libguile/weak-set.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/libguile/weak-set.c b/libguile/weak-set.c
index be49b267e..e6735e054 100644
--- a/libguile/weak-set.c
+++ b/libguile/weak-set.c
@@ -145,6 +145,14 @@ eq_finalizer (void *k, void *s)
weak_set_remove_x (set, scm_ihashq (key, -1), eq_predicate, k);
}
+static void
+symbol_finalizer (void *k, void *s)
+{
+ SCM key = SCM_PACK_POINTER (k);
+ scm_t_weak_set *set = s;
+ weak_set_remove_x (set, scm_i_symbol_hash (key), eq_predicate, k);
+}
+
struct finalizer_data {
scm_t_weak_set *set;
unsigned long hash;
@@ -175,6 +183,9 @@ register_finalizer (scm_t_weak_set *s, unsigned long hash, SCM key)
if (hash == ((scm_ihashq (key, -1) << 1) | 0x1))
scm_i_add_finalizer (SCM2PTR (key), eq_finalizer, s);
+ else if (scm_is_symbol (key) && hash == ((scm_i_symbol_hash (key) << 1) | 0x1))
+ /* Hack for the symbol table, whose hashes are the string hashes. */
+ scm_i_add_finalizer (SCM2PTR (key), symbol_finalizer, s);
else
scm_i_add_finalizer (SCM2PTR (key), equal_finalizer,
make_finalizer_data (s, hash));