diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-05-27 20:47:15 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-05-27 20:47:15 -0700 |
commit | 5a4d281d6701e9f27b67bf9def3842780410ab56 (patch) | |
tree | 153269999a6bb764e8596befd47b8e5c4b9bf1ac /struct.c | |
parent | 3d9e60cb8ba2a9698336ae4697f59e14282a673d (diff) | |
download | txr-5a4d281d6701e9f27b67bf9def3842780410ab56.tar.gz txr-5a4d281d6701e9f27b67bf9def3842780410ab56.tar.bz2 txr-5a4d281d6701e9f27b67bf9def3842780410ab56.zip |
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.
Diffstat (limited to 'struct.c')
-rw-r--r-- | struct.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -1044,17 +1044,17 @@ static val struct_inst_equal(val left, val right) return t; } -static cnum struct_inst_hash(val obj) +static cnum struct_inst_hash(val obj, int *count) { struct struct_inst *si = coerce(struct struct_inst *, obj->co.handle); struct struct_type *st = si->type; - cnum nslots = st->nslots, sl, out = c_num(hash_equal(st->self)); + cnum nslots = st->nslots, sl, out = equal_hash(st->self, count); check_init_lazy_struct(obj, si); for (sl = 0; sl < nslots; sl++) { - val hash = hash_equal(si->slot[sl]); - out += c_num(hash); + cnum hash = equal_hash(si->slot[sl], count); + out += hash; out &= NUM_MAX; } |