From 153b8b35257fb5d68735b5e43e48b0cdb8b15170 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Thu, 15 Jan 2015 09:31:18 -0800 Subject: util/hash_set: Rework the API to know about hashing Previously, the set 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 set 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_set_add(ht, _mesa_pointer_hash(key), key); In the above case, there is no reason why the hash set 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 set will assert that your hash matches what it expects out of the hashing function. This should make it harder to mess up your hashing. This is analygous to 94303a0750 where we did this for hash_table Signed-off-by: Jason Ekstrand Reviewed-by: Matt Turner Reviewed-by: Eric Anholt --- src/glsl/nir/nir_print.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/glsl/nir/nir_print.c') diff --git a/src/glsl/nir/nir_print.c b/src/glsl/nir/nir_print.c index fe5ceeaf035..84bb97957ba 100644 --- a/src/glsl/nir/nir_print.c +++ b/src/glsl/nir/nir_print.c @@ -210,8 +210,7 @@ print_var_decl(nir_variable *var, print_var_state *state, FILE *fp) glsl_print_type(var->type, fp); - struct set_entry *entry = - _mesa_set_search(state->syms, _mesa_hash_string(var->name), var->name); + struct set_entry *entry = _mesa_set_search(state->syms, var->name); char *name; @@ -232,7 +231,7 @@ print_var_decl(nir_variable *var, print_var_state *state, FILE *fp) fprintf(fp, "\n"); - _mesa_set_add(state->syms, _mesa_hash_string(name), name); + _mesa_set_add(state->syms, name); _mesa_hash_table_insert(state->ht, var, name); } @@ -818,7 +817,8 @@ init_print_state(print_var_state *state) { state->ht = _mesa_hash_table_create(NULL, _mesa_hash_pointer, _mesa_key_pointer_equal); - state->syms = _mesa_set_create(NULL, _mesa_key_string_equal); + state->syms = _mesa_set_create(NULL, _mesa_key_hash_string, + _mesa_key_string_equal); state->index = 0; } -- cgit v1.2.3