From 94303a0750f9eaae3fcf598b7bf1320e521898fb Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Mon, 24 Nov 2014 22:19:50 -0800 Subject: util/hash_table: Rework the API to know about hashing Previously, the hash_table API required the user to do all of the hashing of keys as it passed them in. Since the hashing function is intrinsically tied to the comparison function, it makes sense for the hash table to know about it. Also, it makes for a somewhat clumsy API as the user is constantly calling hashing functions many of which have long names. This is especially bad when the standard call looks something like _mesa_hash_table_insert(ht, _mesa_pointer_hash(key), key, data); In the above case, there is no reason why the hash table shouldn't do the hashing for you. We leave the option for you to do your own hashing if it's more efficient, but it's no longer needed. Also, if you do do your own hashing, the hash table will assert that your hash matches what it expects out of the hashing function. This should make it harder to mess up your hashing. v2: change to call the old entrypoint "pre_hashed" rather than "with_hash", like cworth's equivalent change upstream (change by anholt, acked-in-general by Jason). Signed-off-by: Jason Ekstrand Signed-off-by: Eric Anholt Reviewed-by: Eric Anholt --- src/gallium/drivers/vc4/vc4_opt_cse.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'src/gallium/drivers/vc4/vc4_opt_cse.c') diff --git a/src/gallium/drivers/vc4/vc4_opt_cse.c b/src/gallium/drivers/vc4/vc4_opt_cse.c index bebfb6526de..2ca736fe4d5 100644 --- a/src/gallium/drivers/vc4/vc4_opt_cse.c +++ b/src/gallium/drivers/vc4/vc4_opt_cse.c @@ -84,7 +84,7 @@ vc4_find_cse(struct vc4_compile *c, struct hash_table *ht, uint32_t hash = _mesa_hash_data(&key, sizeof(key)); struct hash_entry *entry = - _mesa_hash_table_search(ht, hash, &key); + _mesa_hash_table_search_pre_hashed(ht, hash, &key); if (entry) { if (debug) { @@ -106,7 +106,7 @@ vc4_find_cse(struct vc4_compile *c, struct hash_table *ht, if (!alloc_key) return NULL; memcpy(alloc_key, &key, sizeof(*alloc_key)); - _mesa_hash_table_insert(ht, hash, alloc_key, inst); + _mesa_hash_table_insert_with_hash(ht, hash, alloc_key, inst); if (debug) { fprintf(stderr, "Added to CSE HT: "); @@ -125,7 +125,8 @@ qir_opt_cse(struct vc4_compile *c) struct qinst *last_sf = NULL; uint32_t sf_count = 0, r4_count = 0; - struct hash_table *ht = _mesa_hash_table_create(NULL, inst_key_equals); + struct hash_table *ht = _mesa_hash_table_create(NULL, NULL, + inst_key_equals); if (!ht) return false; -- cgit v1.2.3