summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--glsl_types.cpp31
-rw-r--r--glsl_types.h6
2 files changed, 21 insertions, 16 deletions
diff --git a/glsl_types.cpp b/glsl_types.cpp
index eb9ab820b1..7b8b3e9014 100644
--- a/glsl_types.cpp
+++ b/glsl_types.cpp
@@ -576,29 +576,40 @@ glsl_type::get_instance(unsigned base_type, unsigned rows, unsigned columns)
int
glsl_type::array_key_compare(const void *a, const void *b)
{
- const array_hash_key *const key1 = (array_hash_key *) a;
- const array_hash_key *const key2 = (array_hash_key *) b;
+ const glsl_type *const key1 = (glsl_type *) a;
+ const glsl_type *const key2 = (glsl_type *) b;
- return ((key1->type == key2->type) && (key1->size == key2->size)) ? 0 : 1;
+ /* Return zero is the types match (there is zero difference) or non-zero
+ * otherwise.
+ */
+ return ((key1->fields.array == key2->fields.array)
+ && (key1->length == key2->length)) ? 0 : 1;
}
unsigned
glsl_type::array_key_hash(const void *a)
{
- char buf[sizeof(array_hash_key) + 1];
-
- memcpy(buf, a, sizeof(array_hash_key));
- buf[sizeof(array_hash_key)] = '\0';
+ const glsl_type *const key = (glsl_type *) a;
+
+ const struct {
+ const glsl_type *t;
+ unsigned l;
+ char nul;
+ } hash_key = {
+ key->fields.array,
+ key->length,
+ '\0'
+ };
- return hash_table_string_hash(buf);
+ return hash_table_string_hash(& hash_key);
}
const glsl_type *
glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
{
- array_hash_key key = { base, array_size };
+ const glsl_type key(base, array_size);
if (array_types == NULL) {
array_types = hash_table_ctor(64, array_key_hash, array_key_compare);
@@ -608,7 +619,7 @@ glsl_type::get_array_instance(const glsl_type *base, unsigned array_size)
if (t == NULL) {
t = new glsl_type(base, array_size);
- hash_table_insert(array_types, (void *) t, & key);
+ hash_table_insert(array_types, (void *) t, t);
}
assert(t->base_type == GLSL_TYPE_ARRAY);
diff --git a/glsl_types.h b/glsl_types.h
index 23a04fbe9d..32035f5a44 100644
--- a/glsl_types.h
+++ b/glsl_types.h
@@ -330,12 +330,6 @@ private:
/** Hash table containing the known array types. */
static struct hash_table *array_types;
- /** Structure defining the key type used for array_types hash table. */
- struct array_hash_key {
- const glsl_type *type;
- unsigned size;
- };
-
static int array_key_compare(const void *a, const void *b);
static unsigned array_key_hash(const void *key);
};