compiler/types: Simplify clearing the glsl_type_cache
authorCaio Oliveira <caio.oliveira@intel.com>
Fri, 1 Sep 2023 06:59:03 +0000 (23:59 -0700)
committerMarge Bot <emma+marge@anholt.net>
Wed, 13 Sep 2023 05:16:58 +0000 (05:16 +0000)
Since now all the data referenced by it is allocated with the cache's
mem_ctx, it is sufficient to just free it, and then reset the cache
state to be ready for a next initialization if it happens.

Reviewed-by: Emma Anholt <emma@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25006>

src/compiler/glsl_types.cpp

index dc56d7f..787848d 100644 (file)
@@ -459,13 +459,6 @@ const glsl_type *glsl_type::get_uint16_type() const
                        this->interface_row_major);
 }
 
-static void
-hash_free_type_function(struct hash_entry *entry)
-{
-   glsl_type *type = (glsl_type *) entry->data;
-   delete type;
-}
-
 void
 glsl_type_singleton_init_or_ref()
 {
@@ -488,34 +481,8 @@ glsl_type_singleton_decref()
       return;
    }
 
-   if (glsl_type_cache.explicit_matrix_types != NULL) {
-      _mesa_hash_table_destroy(glsl_type_cache.explicit_matrix_types,
-                               hash_free_type_function);
-      glsl_type_cache.explicit_matrix_types = NULL;
-   }
-
-   if (glsl_type_cache.array_types != NULL) {
-      _mesa_hash_table_destroy(glsl_type_cache.array_types, hash_free_type_function);
-      glsl_type_cache.array_types = NULL;
-   }
-
-   if (glsl_type_cache.struct_types != NULL) {
-      _mesa_hash_table_destroy(glsl_type_cache.struct_types, hash_free_type_function);
-      glsl_type_cache.struct_types = NULL;
-   }
-
-   if (glsl_type_cache.interface_types != NULL) {
-      _mesa_hash_table_destroy(glsl_type_cache.interface_types, hash_free_type_function);
-      glsl_type_cache.interface_types = NULL;
-   }
-
-   if (glsl_type_cache.subroutine_types != NULL) {
-      _mesa_hash_table_destroy(glsl_type_cache.subroutine_types, hash_free_type_function);
-      glsl_type_cache.subroutine_types = NULL;
-   }
-
    ralloc_free(glsl_type_cache.mem_ctx);
-   glsl_type_cache.mem_ctx = NULL;
+   memset(&glsl_type_cache, 0, sizeof(glsl_type_cache));
 
    simple_mtx_unlock(&glsl_type_cache_mutex);
 }