mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-04-29 19:30:36 +02:00
avoid allocating finalizer data for symbols in weak sets
* libguile/weak-set.c (symbol_finalizer, register_finalizer): Add a fast path for symbols, to avoid allocating the finalizer data.
This commit is contained in:
parent
36931b31b5
commit
5077c02d74
1 changed files with 11 additions and 0 deletions
|
@ -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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue