summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2011-08-17 11:48:07 -0700
committerIan Romanick <[email protected]>2011-09-30 15:37:00 -0700
commit1f8f8aef7f30156bbd906be36cdda2e05d8b0a7f (patch)
treeef90c00d406e98f1ca9a1b7f201e1adf539efdce /src
parent16f7bdf5556e739d5a0b6c4c2e2a30bb731f8fc9 (diff)
mesa: Refactor hash_table_{find,remove} to share some code
Signed-off-by: Ian Romanick <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/mesa/program/hash_table.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/src/mesa/program/hash_table.c b/src/mesa/program/hash_table.c
index 877a9e2ffc3..2b09462c0f5 100644
--- a/src/mesa/program/hash_table.c
+++ b/src/mesa/program/hash_table.c
@@ -108,8 +108,8 @@ hash_table_clear(struct hash_table *ht)
}
-void *
-hash_table_find(struct hash_table *ht, const void *key)
+static struct hash_node *
+get_node(struct hash_table *ht, const void *key)
{
const unsigned hash_value = (*ht->hash)(key);
const unsigned bucket = hash_value % ht->num_buckets;
@@ -119,13 +119,20 @@ hash_table_find(struct hash_table *ht, const void *key)
struct hash_node *hn = (struct hash_node *) node;
if ((*ht->compare)(hn->key, key) == 0) {
- return hn->data;
+ return hn;
}
}
return NULL;
}
+void *
+hash_table_find(struct hash_table *ht, const void *key)
+{
+ struct hash_node *hn = get_node(ht, key);
+
+ return (hn == NULL) ? NULL : hn->data;
+}
void
hash_table_insert(struct hash_table *ht, void *data, const void *key)
@@ -145,19 +152,12 @@ hash_table_insert(struct hash_table *ht, void *data, const void *key)
void
hash_table_remove(struct hash_table *ht, const void *key)
{
- const unsigned hash_value = (*ht->hash)(key);
- const unsigned bucket = hash_value % ht->num_buckets;
- struct node *node;
-
- foreach(node, & ht->buckets[bucket]) {
- struct hash_node *hn = (struct hash_node *) node;
-
- if ((*ht->compare)(hn->key, key) == 0) {
- remove_from_list(node);
- free(node);
- return;
- }
- }
+ struct node *node = (struct node *) get_node(ht, key);
+ if (node != NULL) {
+ remove_from_list(node);
+ free(node);
+ return;
+ }
}
void