From f7b513c9b1efa56514bf3d0aa778a141a96f98ff Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ol=C5=A1=C3=A1k?= Date: Sun, 7 Aug 2022 19:29:37 -0400 Subject: [PATCH] cso: inline more functions because some parameters like key_size are literals One function is moved to the header file, the other two functions are inlined manually. Reviewed-by: Pierre-Eric Pelloux-Prayer Reviewed-By: Mike Blumenkrantz Part-of: --- src/gallium/auxiliary/cso_cache/cso_cache.c | 37 ++--------------------------- src/gallium/auxiliary/cso_cache/cso_cache.h | 27 +++++++++++++-------- 2 files changed, 19 insertions(+), 45 deletions(-) diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.c b/src/gallium/auxiliary/cso_cache/cso_cache.c index c40fd1b..4ad9405 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.c +++ b/src/gallium/auxiliary/cso_cache/cso_cache.c @@ -36,14 +36,6 @@ #include "cso_hash.h" -static inline struct cso_hash * -_cso_hash_for_type(struct cso_cache *sc, enum cso_cache_type type) -{ - assert(type < ARRAY_SIZE(sc->hashes)); - return &sc->hashes[type]; -} - - /* Default delete callback. It can also be used by custom callbacks. */ void cso_delete_state(struct pipe_context *pipe, void *state, @@ -114,21 +106,12 @@ cso_insert_state(struct cso_cache *sc, unsigned hash_key, enum cso_cache_type type, void *state) { - struct cso_hash *hash = _cso_hash_for_type(sc, type); + struct cso_hash *hash = &sc->hashes[type]; sanitize_hash(sc, hash, type, sc->max_size); return cso_hash_insert(hash, hash_key, state); } -struct cso_hash_iter -cso_find_state(struct cso_cache *sc, - unsigned hash_key, enum cso_cache_type type) -{ - struct cso_hash *hash = _cso_hash_for_type(sc, type); - return cso_hash_find(hash, hash_key); -} - - void * cso_hash_find_data_from_template(struct cso_hash *hash, unsigned hash_key, @@ -148,22 +131,6 @@ cso_hash_find_data_from_template(struct cso_hash *hash, } -struct cso_hash_iter -cso_find_state_template(struct cso_cache *sc, - unsigned hash_key, enum cso_cache_type type, - const void *templ, unsigned size) -{ - struct cso_hash_iter iter = cso_find_state(sc, hash_key, type); - while (!cso_hash_iter_is_null(iter)) { - void *iter_data = cso_hash_iter_data(iter); - if (!memcmp(iter_data, templ, size)) - return iter; - iter = cso_hash_iter_next(iter); - } - return iter; -} - - void cso_cache_init(struct cso_cache *sc, struct pipe_context *pipe) { @@ -183,7 +150,7 @@ cso_cache_init(struct cso_cache *sc, struct pipe_context *pipe) static void cso_delete_all(struct cso_cache *sc, enum cso_cache_type type) { - struct cso_hash *hash = _cso_hash_for_type(sc, type); + struct cso_hash *hash = &sc->hashes[type]; struct cso_hash_iter iter = cso_hash_first_node(hash); while (!cso_hash_iter_is_null(iter)) { void *state = cso_hash_iter_data(iter); diff --git a/src/gallium/auxiliary/cso_cache/cso_cache.h b/src/gallium/auxiliary/cso_cache/cso_cache.h index 7adbdad..35408e1 100644 --- a/src/gallium/auxiliary/cso_cache/cso_cache.h +++ b/src/gallium/auxiliary/cso_cache/cso_cache.h @@ -167,15 +167,6 @@ cso_insert_state(struct cso_cache *sc, unsigned hash_key, enum cso_cache_type type, void *state); -struct cso_hash_iter -cso_find_state(struct cso_cache *sc, - unsigned hash_key, enum cso_cache_type type); - -struct cso_hash_iter -cso_find_state_template(struct cso_cache *sc, - unsigned hash_key, enum cso_cache_type type, - const void *templ, unsigned size); - void cso_set_maximum_cache_size(struct cso_cache *sc, int number); @@ -184,7 +175,7 @@ cso_delete_state(struct pipe_context *pipe, void *state, enum cso_cache_type type); -static inline unsigned +static ALWAYS_INLINE unsigned cso_construct_key(const void *key, int key_size) { unsigned hash = 0; @@ -199,6 +190,22 @@ cso_construct_key(const void *key, int key_size) return hash; } +static ALWAYS_INLINE struct cso_hash_iter +cso_find_state_template(struct cso_cache *sc, unsigned hash_key, + enum cso_cache_type type, const void *key, + unsigned key_size) +{ + struct cso_hash *hash = &sc->hashes[type]; + struct cso_hash_iter iter = cso_hash_find(hash, hash_key); + + while (!cso_hash_iter_is_null(iter)) { + void *iter_data = cso_hash_iter_data(iter); + if (!memcmp(iter_data, key, key_size)) + return iter; + iter = cso_hash_iter_next(iter); + } + return iter; +} #ifdef __cplusplus } -- 2.7.4