cso: inline more functions because some parameters like key_size are literals
authorMarek Olšák <marek.olsak@amd.com>
Sun, 7 Aug 2022 23:29:37 +0000 (19:29 -0400)
committerMarge Bot <emma+marge@anholt.net>
Wed, 19 Oct 2022 04:56:55 +0000 (04:56 +0000)
One function is moved to the header file, the other two functions are inlined
manually.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19129>

src/gallium/auxiliary/cso_cache/cso_cache.c
src/gallium/auxiliary/cso_cache/cso_cache.h

index c40fd1b..4ad9405 100644 (file)
 #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);
index 7adbdad..35408e1 100644 (file)
@@ -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
 }