From 5a4d281d6701e9f27b67bf9def3842780410ab56 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 27 May 2016 20:47:15 -0700 Subject: Reduce work done by hashing. Curtail traversal of objects and strings. * hash.c (struct hash): hash_fun member takes int * parameter now. (HASH_STR_LIMIT, HASH_REC_LIMIT): New macros. (hash_c_str): Hash only HASH_STR_LIMIT characters. (equal_hash): Becomes extern function. Takes pointer-to-int count argument, which is decremented. Function stops recursing and returns zero when this hits zero. (eql_hash): Also takes int * param, for compatibility with function pointer in struct hash. This parameter is not used, though. (cobj_hash_op): Take pointer-to-count parameter, but ignore it. (hash_hash_op): Take pointer-to-count parameter, decrement and check that it has not hit zero, pass down to equal hash. (hash_grow, gethash_c, gethash, gethash_f, gethash_n, remhash): Initialize a counter to HASH_REC_LIMIT and pass down to hashing function. (hash_eql): Pass down a pointer to a dummy counter to eql_hash. (hash_equal): Initialize a counter to HASH_REC_LIMIT and pass down to hash_equal. * hash.h (equal_hash): Declared. * lib.h (cobj_ops): hash member takes int * parameter. (cobj_hash_op): Declaration updated with new param. * struct.c (struct_inst_hash): Takes new int * parameter for count. Calls equal_hash instead of hash_equal, eliminating c_num calls; pointer to count is passed to equal_hash. --- lib.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib.h') diff --git a/lib.h b/lib.h index 18f7f6d9..a004926b 100644 --- a/lib.h +++ b/lib.h @@ -226,7 +226,7 @@ struct cobj_ops { void (*print)(val self, val stream, val pretty); void (*destroy)(val self); void (*mark)(val self); - cnum (*hash)(val self); + cnum (*hash)(val self, int *count); val (*equalsub)(val self); }; @@ -245,7 +245,7 @@ void cobj_print_op(val, val, val); void cobj_destroy_stub_op(val); void cobj_destroy_free_op(val); void cobj_mark_op(val); -cnum cobj_hash_op(val); +cnum cobj_hash_op(val, int *); struct env { obj_common; -- cgit v1.2.3