From 2ab6f0183ba2fb014cc028aeb8afb6a2aba7c059 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 14 Feb 2019 07:44:35 -0800 Subject: Optimize hash operation with unsafe car/cdr. The associative lists that make up the chains of a hash table are guaranteed to be made of conses. We can use unsafe versions of car, cdr, rplaca and rplacd to speed up hash operations. * eval.c (op_dohash): Use unsafe operations on hash cell. * filter.c (trie_compress, regex_from_trie): Likewise. * hash.c (hash_equal_op, hash_print_op, hash_mark, hash_grow, hash_assoc, hash_assql, copy_hash_chain, gethash, inhash, gethash_n, sethash, remhash, hash_next, maphash, do_weak_tables, group_by, group_reduce, hash_keys_lazy, hash_keys, hash_values_lazy, hash_values, hash_pairs_lazy, hash_pairs, hash_alist_lazy, hash_uni, hash_diff, hash_symdiff, hash_isec, hash_subset, hash_update, hash_update_1, hash_revget): Likewise. * lib.c (us_rplaca, us_rplacd): New functions. (package_local_symbols, package_foreign_symbols, where, populate_obj_hash, obj_hash_merge): Use unsafe operations on hash cell * lib.h (us_rplaca, us_rplacd): Declared. * parser.c (circ_backpatch, get_visible_syms): Use unsafe operations on hash cell. * struct.c (method_name, get_slot_syms): Likewise. --- struct.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'struct.c') diff --git a/struct.c b/struct.c index d2407ace..9fa3b4f7 100644 --- a/struct.c +++ b/struct.c @@ -1550,8 +1550,8 @@ val method_name(val fun) val sth_cell; while ((sth_cell = hash_next(sth_iter))) { - val sym = car(sth_cell); - val stype = cdr(sth_cell); + val sym = us_car(sth_cell); + val stype = us_cdr(sth_cell); val sl_iter; struct struct_type *st = coerce(struct struct_type *, stype->co.handle); @@ -1596,7 +1596,7 @@ val get_slot_syms(val package, val is_current, val method_only) val sth_cell; while ((sth_cell = hash_next(sth_iter))) { - val stype = cdr(sth_cell); + val stype = us_cdr(sth_cell); val sl_iter; struct struct_type *st = coerce(struct struct_type *, stype->co.handle); -- cgit v1.2.3