aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary/cso_cache
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2020-01-21 20:10:43 -0500
committerMarek Olšák <[email protected]>2020-02-14 18:16:28 -0500
commita8bbf1054093f638c83a27696b841d053a83ba72 (patch)
treee3c446cb77def93d325d4fe12790cc22dbe539ae /src/gallium/auxiliary/cso_cache
parentf8594a06e4a2e65c3fc458d7ddce374e9a093b6e (diff)
gallium/cso_hash: make cso_hash declared within structures instead of alloc'd
This removes one level of indirection. Reviewed-by: Pierre-Eric Pelloux-Prayer <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3829>
Diffstat (limited to 'src/gallium/auxiliary/cso_cache')
-rw-r--r--src/gallium/auxiliary/cso_cache/cso_cache.c12
-rw-r--r--src/gallium/auxiliary/cso_cache/cso_hash.c19
-rw-r--r--src/gallium/auxiliary/cso_cache/cso_hash.h4
3 files changed, 13 insertions, 22 deletions
diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.c b/src/gallium/auxiliary/cso_cache/cso_cache.c
index 4c1a76d9022..6cae21ca871 100644
--- a/src/gallium/auxiliary/cso_cache/cso_cache.c
+++ b/src/gallium/auxiliary/cso_cache/cso_cache.c
@@ -37,7 +37,7 @@
struct cso_cache {
- struct cso_hash *hashes[CSO_CACHE_MAX];
+ struct cso_hash hashes[CSO_CACHE_MAX];
int max_size;
cso_sanitize_callback sanitize_cb;
@@ -82,9 +82,7 @@ unsigned cso_construct_key(void *item, int item_size)
static inline struct cso_hash *_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_type type)
{
- struct cso_hash *hash;
- hash = sc->hashes[type];
- return hash;
+ return &sc->hashes[type];
}
static void delete_blend_state(void *state, UNUSED void *data)
@@ -252,7 +250,7 @@ struct cso_cache *cso_cache_create(void)
sc->max_size = 4096;
for (i = 0; i < CSO_CACHE_MAX; i++)
- sc->hashes[i] = cso_hash_create();
+ cso_hash_init(&sc->hashes[i]);
sc->sanitize_cb = sanitize_cb;
sc->sanitize_data = 0;
@@ -292,7 +290,7 @@ void cso_cache_delete(struct cso_cache *sc)
cso_for_each_state(sc, CSO_VELEMENTS, delete_velements, 0);
for (i = 0; i < CSO_CACHE_MAX; i++)
- cso_hash_delete(sc->hashes[i]);
+ cso_hash_deinit(&sc->hashes[i]);
FREE(sc);
}
@@ -304,7 +302,7 @@ void cso_set_maximum_cache_size(struct cso_cache *sc, int number)
sc->max_size = number;
for (i = 0; i < CSO_CACHE_MAX; i++)
- sanitize_hash(sc, sc->hashes[i], i, sc->max_size);
+ sanitize_hash(sc, &sc->hashes[i], i, sc->max_size);
}
int cso_maximum_cache_size(const struct cso_cache *sc)
diff --git a/src/gallium/auxiliary/cso_cache/cso_hash.c b/src/gallium/auxiliary/cso_cache/cso_hash.c
index 9d633243ac9..753cd89f1ed 100644
--- a/src/gallium/auxiliary/cso_cache/cso_hash.c
+++ b/src/gallium/auxiliary/cso_cache/cso_hash.c
@@ -199,17 +199,11 @@ struct cso_hash_iter cso_hash_insert(struct cso_hash *hash,
}
}
-struct cso_hash * cso_hash_create(void)
+bool cso_hash_init(struct cso_hash *hash)
{
- struct cso_hash *hash = MALLOC_STRUCT(cso_hash);
- if (!hash)
- return NULL;
-
hash->data.d = MALLOC_STRUCT(cso_hash_data);
- if (!hash->data.d) {
- FREE(hash);
- return NULL;
- }
+ if (!hash->data.d)
+ return false;
hash->data.d->fakeNext = 0;
hash->data.d->buckets = 0;
@@ -218,11 +212,10 @@ struct cso_hash * cso_hash_create(void)
hash->data.d->userNumBits = (short)MinNumBits;
hash->data.d->numBits = 0;
hash->data.d->numBuckets = 0;
-
- return hash;
+ return true;
}
-void cso_hash_delete(struct cso_hash *hash)
+void cso_hash_deinit(struct cso_hash *hash)
{
struct cso_node *e_for_x = (struct cso_node *)(hash->data.d);
struct cso_node **bucket = (struct cso_node **)(hash->data.d->buckets);
@@ -237,7 +230,7 @@ void cso_hash_delete(struct cso_hash *hash)
}
FREE(hash->data.d->buckets);
FREE(hash->data.d);
- FREE(hash);
+ hash->data.d = NULL;
}
unsigned cso_hash_iter_key(struct cso_hash_iter iter)
diff --git a/src/gallium/auxiliary/cso_cache/cso_hash.h b/src/gallium/auxiliary/cso_cache/cso_hash.h
index e41cb9e0af3..b86e11c5fd5 100644
--- a/src/gallium/auxiliary/cso_cache/cso_hash.h
+++ b/src/gallium/auxiliary/cso_cache/cso_hash.h
@@ -79,8 +79,8 @@ struct cso_hash_data {
int numBuckets;
};
-struct cso_hash *cso_hash_create(void);
-void cso_hash_delete(struct cso_hash *hash);
+bool cso_hash_init(struct cso_hash *hash);
+void cso_hash_deinit(struct cso_hash *hash);
int cso_hash_size(struct cso_hash *hash);