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. --- hash.h | 1 + 1 file changed, 1 insertion(+) (limited to 'hash.h') diff --git a/hash.h b/hash.h index a1ec19fc..29ff19d7 100644 --- a/hash.h +++ b/hash.h @@ -26,6 +26,7 @@ extern val weak_keys_k, weak_vals_k, equal_based_k; +cnum equal_hash(val obj, int *count); val make_hash(val weak_keys, val weak_vals, val equal_based); val make_similar_hash(val existing); val copy_hash(val existing); -- cgit v1.2.3