[Mesa-dev] [PATCH 14/24] cso: inline a few frequently-used functions
Marek Olšák
maraeo at gmail.com
Mon Jun 12 18:18:45 UTC 2017
From: Marek Olšák <marek.olsak at amd.com>
---
src/gallium/auxiliary/cso_cache/cso_hash.c | 27 ---------------------------
src/gallium/auxiliary/cso_cache/cso_hash.h | 30 ++++++++++++++++++++++++++----
2 files changed, 26 insertions(+), 31 deletions(-)
diff --git a/src/gallium/auxiliary/cso_cache/cso_hash.c b/src/gallium/auxiliary/cso_cache/cso_hash.c
index 2a3f361..4d3e261 100644
--- a/src/gallium/auxiliary/cso_cache/cso_hash.c
+++ b/src/gallium/auxiliary/cso_cache/cso_hash.c
@@ -66,43 +66,30 @@ static int countBits(int hint)
}
if (numBits >= (int)sizeof(prime_deltas)) {
numBits = sizeof(prime_deltas) - 1;
} else if (primeForNumBits(numBits) < hint) {
++numBits;
}
return numBits;
}
-struct cso_node {
- struct cso_node *next;
- unsigned key;
- void *value;
-};
-
struct cso_hash_data {
struct cso_node *fakeNext;
struct cso_node **buckets;
int size;
int nodeSize;
short userNumBits;
short numBits;
int numBuckets;
};
-struct cso_hash {
- union {
- struct cso_hash_data *d;
- struct cso_node *e;
- } data;
-};
-
static void *cso_data_allocate_node(struct cso_hash_data *hash)
{
return MALLOC(hash->nodeSize);
}
static void cso_free_node(struct cso_node *node)
{
FREE(node);
}
@@ -286,27 +273,20 @@ struct cso_hash_iter cso_hash_find(struct cso_hash *hash,
return iter;
}
unsigned cso_hash_iter_key(struct cso_hash_iter iter)
{
if (!iter.node || iter.hash->data.e == iter.node)
return 0;
return iter.node->key;
}
-void * cso_hash_iter_data(struct cso_hash_iter iter)
-{
- if (!iter.node || iter.hash->data.e == iter.node)
- return 0;
- return iter.node->value;
-}
-
static struct cso_node *cso_hash_data_next(struct cso_node *node)
{
union {
struct cso_node *next;
struct cso_node *e;
struct cso_hash_data *d;
} a;
int start;
struct cso_node **bucket;
int n;
@@ -367,27 +347,20 @@ static struct cso_node *cso_hash_data_prev(struct cso_node *node)
debug_printf("iterating backward beyond first element\n");
return a.e;
}
struct cso_hash_iter cso_hash_iter_next(struct cso_hash_iter iter)
{
struct cso_hash_iter next = {iter.hash, cso_hash_data_next(iter.node)};
return next;
}
-int cso_hash_iter_is_null(struct cso_hash_iter iter)
-{
- if (!iter.node || iter.node == iter.hash->data.e)
- return 1;
- return 0;
-}
-
void * cso_hash_take(struct cso_hash *hash,
unsigned akey)
{
struct cso_node **node = cso_hash_find_node(hash, akey);
if (*node != hash->data.e) {
void *t = (*node)->value;
struct cso_node *next = (*node)->next;
cso_free_node(*node);
*node = next;
--hash->data.d->size;
diff --git a/src/gallium/auxiliary/cso_cache/cso_hash.h b/src/gallium/auxiliary/cso_cache/cso_hash.h
index e58981c..d6eeb04 100644
--- a/src/gallium/auxiliary/cso_cache/cso_hash.h
+++ b/src/gallium/auxiliary/cso_cache/cso_hash.h
@@ -44,23 +44,32 @@
#ifndef CSO_HASH_H
#define CSO_HASH_H
#include "pipe/p_compiler.h"
#ifdef __cplusplus
extern "C" {
#endif
-struct cso_hash;
-struct cso_node;
+struct cso_node {
+ struct cso_node *next;
+ unsigned key;
+ void *value;
+};
+struct cso_hash {
+ union {
+ struct cso_hash_data *d;
+ struct cso_node *e;
+ } data;
+};
struct cso_hash_iter {
struct cso_hash *hash;
struct cso_node *node;
};
struct cso_hash *cso_hash_create(void);
void cso_hash_delete(struct cso_hash *hash);
@@ -95,35 +104,48 @@ struct cso_hash_iter cso_hash_first_node(struct cso_hash *hash);
* Return an iterator pointing to the first entry in the collision list.
*/
struct cso_hash_iter cso_hash_find(struct cso_hash *hash, unsigned key);
/**
* Returns true if a value with the given key exists in the hash
*/
boolean cso_hash_contains(struct cso_hash *hash, unsigned key);
-int cso_hash_iter_is_null(struct cso_hash_iter iter);
unsigned cso_hash_iter_key(struct cso_hash_iter iter);
-void *cso_hash_iter_data(struct cso_hash_iter iter);
struct cso_hash_iter cso_hash_iter_next(struct cso_hash_iter iter);
struct cso_hash_iter cso_hash_iter_prev(struct cso_hash_iter iter);
/**
* Convenience routine to iterate over the collision list while doing a memory
* comparison to see which entry in the list is a direct copy of our template
* and returns that entry.
*/
void *cso_hash_find_data_from_template( struct cso_hash *hash,
unsigned hash_key,
void *templ,
int size );
+static inline int
+cso_hash_iter_is_null(struct cso_hash_iter iter)
+{
+ if (!iter.node || iter.node == iter.hash->data.e)
+ return 1;
+ return 0;
+}
+
+static inline void *
+cso_hash_iter_data(struct cso_hash_iter iter)
+{
+ if (!iter.node || iter.hash->data.e == iter.node)
+ return 0;
+ return iter.node->value;
+}
#ifdef __cplusplus
}
#endif
#endif
--
2.7.4
More information about the mesa-dev
mailing list