summaryrefslogtreecommitdiff
path: root/libguile/symbols.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2011-01-07 08:42:15 -0800
committerAndy Wingo <wingo@pobox.com>2011-01-07 09:18:37 -0800
commit17072fd2c6acad1d4f2b5c98eb0d62911ea07406 (patch)
treedf0386a987c7dc675fc09f36a08f93a736edf57a /libguile/symbols.c
parent6efbc280c56a1c318717723423e2b4e2654c353a (diff)
downloadguile-17072fd2c6acad1d4f2b5c98eb0d62911ea07406.tar.gz
lookup_interned_symbol uses get_handle_by_hash
* libguile/symbols.c (lookup_interned_symbol): Change to use scm_hash_fn_get_handle_by_hash.
Diffstat (limited to 'libguile/symbols.c')
-rw-r--r--libguile/symbols.c46
1 files changed, 18 insertions, 28 deletions
diff --git a/libguile/symbols.c b/libguile/symbols.c
index 769e397ab..ccd54d16c 100644
--- a/libguile/symbols.c
+++ b/libguile/symbols.c
@@ -76,35 +76,26 @@ scm_i_hash_symbol (SCM obj, unsigned long n, void *closure)
struct string_lookup_data
{
+ SCM string;
unsigned long string_hash;
};
-static unsigned long
-string_lookup_hash_fn (SCM obj, unsigned long max, void *closure)
-{
- struct string_lookup_data *data = closure;
-
- if (scm_is_symbol (obj))
- return scm_i_symbol_hash (obj) % max;
- else
- return data->string_hash % max;
-}
-
-static SCM
-string_lookup_assoc_fn (SCM obj, SCM alist, void *closure)
+static int
+string_lookup_predicate_fn (SCM sym, void *closure)
{
struct string_lookup_data *data = closure;
- for (; !scm_is_null (alist); alist = SCM_CDR (alist))
+ if (scm_i_symbol_hash (sym) == data->string_hash
+ && scm_i_symbol_length (sym) == scm_i_string_length (data->string))
{
- SCM sym = SCM_CAAR (alist);
-
- if (scm_i_symbol_hash (sym) == data->string_hash
- && scm_is_true (scm_string_equal_p (scm_symbol_to_string (sym), obj)))
- return SCM_CAR (alist);
+ size_t n = scm_i_symbol_length (sym);
+ while (n--)
+ if (scm_i_symbol_ref (sym, n) != scm_i_string_ref (data->string, n))
+ return 0;
+ return 1;
}
-
- return SCM_BOOL_F;
+ else
+ return 0;
}
static SCM
@@ -113,17 +104,16 @@ lookup_interned_symbol (SCM name, unsigned long raw_hash)
struct string_lookup_data data;
SCM handle;
+ data.string = name;
data.string_hash = raw_hash;
/* Strictly speaking, we should take a lock here. But instead we rely
on the fact that if this fails, we do take the lock on the
- intern_symbol path; and since nothing deletes from the hash table,
- we should be OK. Though, weak pair deletion is somewhat
- worrying... */
- handle = scm_hash_fn_get_handle (symbols, name,
- string_lookup_hash_fn,
- string_lookup_assoc_fn,
- &data);
+ intern_symbol path; and since nothing deletes from the hash table
+ except GC, we should be OK. */
+ handle = scm_hash_fn_get_handle_by_hash (symbols, raw_hash,
+ string_lookup_predicate_fn,
+ &data);
if (scm_is_true (handle))
return SCM_CAR (handle);