summaryrefslogtreecommitdiffstats
path: root/ftw.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-06-22 06:48:43 -0700
committerKaz Kylheku <kaz@kylheku.com>2018-06-22 06:48:43 -0700
commitaf873831f7585fc0843341951703a8edbf2d95bb (patch)
treec18f931d61c5f652d7bd846621f764e06ce14785 /ftw.c
parent8628fd0133fd7796491b2927023a97c3ec5f5ce3 (diff)
downloadtxr-af873831f7585fc0843341951703a8edbf2d95bb.tar.gz
txr-af873831f7585fc0843341951703a8edbf2d95bb.tar.bz2
txr-af873831f7585fc0843341951703a8edbf2d95bb.zip
hash: move ops into static structure + bug found.
The four hash operations (hash, equal, assoc and acons) are moved out of the hash instance and into a static table of operations. This means we have to go through one more indirection when calling them, but we save some space and shorten initialization. A bug is fixed here: the copy_hash function was only copying three out of these four functions; the equal operation was left uninitialized eposing the hash equality operation to corrupt behavior. Now that function just copies the hops pointer, so all is well. * hash.c (struct hash_ops): New struct type. (hash_ops_init): New macro. (struct hash): hash_fun, equal_fun, assoc_fun and assoc_new_c fun members removed. New member hops. (hash_eql_ops, hash_equal_ops): New static structures. (hash_equal_op): Compare the hops pointers rather than just the hash_fun: if two hashes have different hops pointers, they are different, period. Indirect through ops for calling equal fun and others. (hash_hash_op): Include the hops pointer in the hash, rather than the hash_fun pointer. (hash_print_op): Test for hash type (equal based or eql based) now done by comparing the hops pointer to one of the two static structures, rather than hash_fun to one of two functions. (make_hash, make_similar_hash, copy_hash): Initialize hops; remove initializations for the four functions. (gethash_c, gethash_e, remhash): Indirect through hops to invoke hash operations. (hash_uni, hash_diff, hash_isec): Incompatible hash check based on comparing hops pointer rather than hash_fun.
Diffstat (limited to 'ftw.c')
0 files changed, 0 insertions, 0 deletions