From 0f54621564586043cccfd29f0e7b17c427faf3ee Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Fri, 26 May 2023 21:54:53 -0700 Subject: [PATCH] compiler/types: Make key in subroutine_name more effective Use the string itself as a key for searching -- and the internal allocated name as a key when storing. Because record_key_hash doesn't consider the name field, which is the only used field for a SUBROUTINE type, the hash key was always the same for all types. Using the name fixes this. Reviewed-by: Jesse Natalie Part-of: --- src/compiler/glsl_types.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/compiler/glsl_types.cpp b/src/compiler/glsl_types.cpp index d639aa3..47de0da 100644 --- a/src/compiler/glsl_types.cpp +++ b/src/compiler/glsl_types.cpp @@ -1527,22 +1527,20 @@ glsl_type::get_interface_instance(const glsl_struct_field *fields, const glsl_type * glsl_type::get_subroutine_instance(const char *subroutine_name) { - const glsl_type key(subroutine_name); - simple_mtx_lock(&glsl_type::hash_mutex); assert(glsl_type_users > 0); if (subroutine_types == NULL) { - subroutine_types = _mesa_hash_table_create(NULL, record_key_hash, - record_key_compare); + subroutine_types = _mesa_hash_table_create(NULL, _mesa_hash_string, + _mesa_key_string_equal); } const struct hash_entry *entry = _mesa_hash_table_search(subroutine_types, - &key); + subroutine_name); if (entry == NULL) { const glsl_type *t = new glsl_type(subroutine_name); - entry = _mesa_hash_table_insert(subroutine_types, t, (void *) t); + entry = _mesa_hash_table_insert(subroutine_types, t->name, (void *) t); } assert(((glsl_type *) entry->data)->base_type == GLSL_TYPE_SUBROUTINE); -- 2.7.4