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 <pierre-eric.pelloux-prayer@amd.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3829>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3829>
node->next = *anextNode;
*anextNode = node;
node->next = *anextNode;
*anextNode = node;
struct cso_hash_iter cso_hash_insert(struct cso_hash *hash,
unsigned key, void *data)
{
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);
struct cso_node **nextNode = cso_hash_find_node(hash, key);
struct cso_node *node = cso_hash_create_node(hash, key, data, nextNode);
-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)
{
}
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++;
while (n--) {
struct cso_node *cur = *bucket++;
- 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)
{
}
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;
}
return 0;
return iter.node->key;
}
{
struct cso_node **node = cso_hash_find_node(hash, 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;
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);
struct cso_hash_iter cso_hash_first_node(struct cso_hash *hash)
{
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 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)
}
struct cso_hash_iter cso_hash_erase(struct cso_hash *hash, struct cso_hash_iter iter)
struct cso_node *node = iter.node;
struct cso_node **node_ptr;
struct cso_node *node = iter.node;
struct cso_node **node_ptr;
- if (node == hash->data.e)
return iter;
ret = cso_hash_iter_next(ret);
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);
while (*node_ptr != node)
node_ptr = &(*node_ptr)->next;
*node_ptr = node->next;
FREE(node);
return ret;
}
bool cso_hash_contains(struct cso_hash *hash, unsigned key)
{
struct cso_node **node = cso_hash_find_node(hash, key);
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;
-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_iter {
struct cso_hash *hash;
struct cso_node *node;
-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);
void cso_hash_deinit(struct cso_hash *hash);
static inline bool
cso_hash_iter_is_null(struct cso_hash_iter iter)
{
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)
{
}
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;
}
return NULL;
return iter.node->value;
}
{
struct cso_node **node;
{
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 = &(*node)->next;
} else {
- if (!cso_hash_init(&ht->cso)) {
- FREE(ht);
- return NULL;
- }
+ cso_hash_init(&ht->cso);
ht->hash = hash;
ht->compare = compare;
ht->hash = hash;
ht->compare = compare;
if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE)
{ /* or 2D array */
if(pt->target == PIPE_TEXTURE_3D || pt->target == PIPE_TEXTURE_CUBE)
{ /* or 2D array */
- if (!us->u.hash.data.d)
cso_hash_init(&us->u.hash);
ps = cso_hash_iter_data(cso_hash_find(&us->u.hash, (layer << 8) | level));
cso_hash_init(&us->u.hash);
ps = cso_hash_iter_data(cso_hash_find(&us->u.hash, (layer << 8) | level));