diff options
author | Dirk Herrmann <dirk@dirk-herrmanns-seiten.de> | 2002-07-24 16:34:43 +0000 |
---|---|---|
committer | Dirk Herrmann <dirk@dirk-herrmanns-seiten.de> | 2002-07-24 16:34:43 +0000 |
commit | 35060ae90ef2b79bc7f9cd0ca1b820f775e51730 (patch) | |
tree | 19658ad31b4ef8d822cc47b64768e1edd5e183e6 /libguile/environments.c | |
parent | 6a5354407299c4faf8df61235a2867a8db5aa7e3 (diff) | |
download | guile-35060ae90ef2b79bc7f9cd0ca1b820f775e51730.tar.gz |
* environments.c (remove_key_from_alist): Removed.
(obarray_remove): Simplified.
Diffstat (limited to 'libguile/environments.c')
-rw-r--r-- | libguile/environments.c | 60 |
1 files changed, 7 insertions, 53 deletions
diff --git a/libguile/environments.c b/libguile/environments.c index 26cf424e2..fadfbc6de 100644 --- a/libguile/environments.c +++ b/libguile/environments.c @@ -46,6 +46,7 @@ #include "libguile/eval.h" #include "libguile/gh.h" #include "libguile/hash.h" +#include "libguile/list.h" #include "libguile/ports.h" #include "libguile/smob.h" #include "libguile/symbols.h" @@ -587,49 +588,6 @@ obarray_retrieve (SCM obarray, SCM sym) return SCM_UNDEFINED; } -/* - Remove first occurance of KEY from (cdr ALIST), - return (KEY . VAL) if found, otherwise return #f - - PRECONDITION: - - length (ALIST) >= 1 - - This could also be done by combining scm_delq1_x () and - scm_sloppy_assq(), at the cost of walking the list another time. - */ -static -SCM -remove_key_from_alist (SCM alist, SCM key) -{ - SCM cell_cdr = alist; - alist =SCM_CDR (alist); - - /* - inv: cdr(cell_cdr) == alist - */ - while (!SCM_NULLP (alist)) - { - if (SCM_EQ_P(SCM_CAAR (alist), key)) - { - SCM entry = SCM_CAR(alist); - SCM_SETCDR(cell_cdr, SCM_CDR (alist)); - - return entry; - } - else - { - cell_cdr = SCM_CDR (cell_cdr); - } - - if (!SCM_NULLP(alist)) - alist = SCM_CDR (alist); - } - - return SCM_BOOL_F; -} - - /* * Remove entry from obarray. If the symbol was found and removed, the old @@ -640,19 +598,15 @@ obarray_remove (SCM obarray, SCM sym) { size_t hash = SCM_SYMBOL_HASH (sym) % SCM_VECTOR_LENGTH (obarray); SCM table_entry = SCM_VELTS (obarray)[hash]; + SCM handle = scm_sloppy_assq (sym, table_entry); - if (SCM_NULLP(table_entry)) - return SCM_BOOL_F; - - if (SCM_EQ_P (SCM_CAAR (table_entry), sym)) + if (SCM_CONSP (handle)) { - SCM_VECTOR_SET (obarray, hash, SCM_CDR(table_entry)); - return SCM_CAR(table_entry); - } - else - { - return remove_key_from_alist (table_entry, sym); + SCM new_table_entry = scm_delq1_x (handle, table_entry); + SCM_VECTOR_SET (obarray, hash, new_table_entry); } + + return handle; } |