diff options
author | Marek Olšák <[email protected]> | 2020-01-21 22:53:13 -0500 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2020-02-14 18:16:28 -0500 |
commit | e395ce03e92b707bef7080eae3c2daa7d9760e70 (patch) | |
tree | a06950e73a756abc5d8e89c6a554d96e38d9243a /src/gallium/auxiliary/cso_cache | |
parent | e0bb7b87e26d6618d75d37a4fe2c4a271d075dbb (diff) |
gallium/cso_hash: remove another layer of pointer indirection
Convert this:
struct cso_hash {
union {
struct cso_hash_data *d;
struct cso_node *e;
} data;
};
to this:
struct cso_hash {
struct cso_hash_data data;
struct cso_node *end;
};
1) data is not a pointer anymore.
2) "end" points to "data" and acts as the end of the linked list.
3) This code is still crazy.
Acked-by: Pierre-Eric Pelloux-Prayer <[email protected]>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3829>
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_hash.c | 54 | ||||
-rw-r--r-- | src/gallium/auxiliary/cso_cache/cso_hash.h | 28 |
2 files changed, 37 insertions, 45 deletions
diff --git a/src/gallium/auxiliary/cso_cache/cso_hash.c b/src/gallium/auxiliary/cso_cache/cso_hash.c index e42f1feb9b5..2939d719042 100644 --- a/src/gallium/auxiliary/cso_cache/cso_hash.c +++ b/src/gallium/auxiliary/cso_cache/cso_hash.c @@ -88,7 +88,7 @@ cso_hash_create_node(struct cso_hash *hash, node->next = *anextNode; *anextNode = node; - ++hash->data.d->size; + ++hash->data.size; return node; } @@ -173,7 +173,7 @@ static struct cso_node *cso_data_first_node(struct cso_hash_data *hash) struct cso_hash_iter cso_hash_insert(struct cso_hash *hash, unsigned key, void *data) { - cso_data_might_grow(hash->data.d); + cso_data_might_grow(&hash->data); struct cso_node **nextNode = cso_hash_find_node(hash, key); struct cso_node *node = cso_hash_create_node(hash, key, data, nextNode); @@ -186,26 +186,22 @@ struct cso_hash_iter cso_hash_insert(struct cso_hash *hash, return iter; } -bool cso_hash_init(struct cso_hash *hash) +void cso_hash_init(struct cso_hash *hash) { - hash->data.d = MALLOC_STRUCT(cso_hash_data); - if (!hash->data.d) - return false; - - hash->data.d->fakeNext = 0; - hash->data.d->buckets = 0; - hash->data.d->size = 0; - hash->data.d->userNumBits = (short)MinNumBits; - hash->data.d->numBits = 0; - hash->data.d->numBuckets = 0; - return true; + hash->data.fakeNext = 0; + hash->data.buckets = 0; + hash->data.size = 0; + hash->data.userNumBits = (short)MinNumBits; + hash->data.numBits = 0; + hash->data.numBuckets = 0; + hash->end = (struct cso_node*)&hash->data; } void cso_hash_deinit(struct cso_hash *hash) { - struct cso_node *e_for_x = (struct cso_node *)hash->data.d; - struct cso_node **bucket = hash->data.d->buckets; - int n = hash->data.d->numBuckets; + struct cso_node *e_for_x = hash->end; + struct cso_node **bucket = hash->data.buckets; + int n = hash->data.numBuckets; while (n--) { struct cso_node *cur = *bucket++; @@ -215,14 +211,12 @@ void cso_hash_deinit(struct cso_hash *hash) cur = next; } } - FREE(hash->data.d->buckets); - FREE(hash->data.d); - hash->data.d = NULL; + FREE(hash->data.buckets); } unsigned cso_hash_iter_key(struct cso_hash_iter iter) { - if (!iter.node || iter.hash->data.e == iter.node) + if (!iter.node || iter.hash->end == iter.node) return 0; return iter.node->key; } @@ -299,13 +293,13 @@ 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) { + if (*node != hash->end) { void *t = (*node)->value; struct cso_node *next = (*node)->next; FREE(*node); *node = next; - --hash->data.d->size; - cso_data_has_shrunk(hash->data.d); + --hash->data.size; + cso_data_has_shrunk(&hash->data); return t; } return NULL; @@ -320,13 +314,13 @@ struct cso_hash_iter cso_hash_iter_prev(struct cso_hash_iter iter) struct cso_hash_iter cso_hash_first_node(struct cso_hash *hash) { - struct cso_hash_iter iter = {hash, cso_data_first_node(hash->data.d)}; + struct cso_hash_iter iter = {hash, cso_data_first_node(&hash->data)}; return iter; } int cso_hash_size(struct cso_hash *hash) { - return hash->data.d->size; + return hash->data.size; } struct cso_hash_iter cso_hash_erase(struct cso_hash *hash, struct cso_hash_iter iter) @@ -335,21 +329,21 @@ struct cso_hash_iter cso_hash_erase(struct cso_hash *hash, struct cso_hash_iter struct cso_node *node = iter.node; struct cso_node **node_ptr; - if (node == hash->data.e) + if (node == hash->end) return iter; ret = cso_hash_iter_next(ret); - node_ptr = &hash->data.d->buckets[node->key % hash->data.d->numBuckets]; + node_ptr = &hash->data.buckets[node->key % hash->data.numBuckets]; while (*node_ptr != node) node_ptr = &(*node_ptr)->next; *node_ptr = node->next; FREE(node); - --hash->data.d->size; + --hash->data.size; return ret; } bool cso_hash_contains(struct cso_hash *hash, unsigned key) { struct cso_node **node = cso_hash_find_node(hash, key); - return *node != hash->data.e; + return *node != hash->end; } diff --git a/src/gallium/auxiliary/cso_cache/cso_hash.h b/src/gallium/auxiliary/cso_cache/cso_hash.h index 23cf5c8254e..f50d69d47ab 100644 --- a/src/gallium/auxiliary/cso_cache/cso_hash.h +++ b/src/gallium/auxiliary/cso_cache/cso_hash.h @@ -57,13 +57,6 @@ struct cso_node { 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; @@ -78,7 +71,12 @@ struct cso_hash_data { int numBuckets; }; -bool cso_hash_init(struct cso_hash *hash); +struct cso_hash { + struct cso_hash_data data; + struct cso_node *end; +}; + +void cso_hash_init(struct cso_hash *hash); void cso_hash_deinit(struct cso_hash *hash); @@ -135,13 +133,13 @@ struct cso_node *cso_hash_data_next(struct cso_node *node); static inline bool cso_hash_iter_is_null(struct cso_hash_iter iter) { - return !iter.node || iter.node == iter.hash->data.e; + return !iter.node || iter.node == iter.hash->end; } static inline void * cso_hash_iter_data(struct cso_hash_iter iter) { - if (!iter.node || iter.hash->data.e == iter.node) + if (!iter.node || iter.hash->end == iter.node) return NULL; return iter.node->value; } @@ -151,13 +149,13 @@ cso_hash_find_node(struct cso_hash *hash, unsigned akey) { struct cso_node **node; - if (hash->data.d->numBuckets) { - node = &hash->data.d->buckets[akey % hash->data.d->numBuckets]; - assert(*node == hash->data.e || (*node)->next); - while (*node != hash->data.e && (*node)->key != akey) + if (hash->data.numBuckets) { + node = &hash->data.buckets[akey % hash->data.numBuckets]; + assert(*node == hash->end || (*node)->next); + while (*node != hash->end && (*node)->key != akey) node = &(*node)->next; } else { - node = &hash->data.e; + node = &hash->end; } return node; } |