summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas Helland <[email protected]>2016-08-18 21:51:40 +0200
committerTimothy Arceri <[email protected]>2016-09-12 10:48:35 +1000
commiteef2be6822c3409f8418c77f2278ea84492282f2 (patch)
treebc6d08af7e757629006e29d91e3960891291da89 /src
parentddb8639b18e836b904cda857d787c05ab8b0db7b (diff)
mesa: Convert string_to_uint_map to the util hash table
And remove the now unused hash_table_replace. V2: Actually do the equivalent thing, and don't leak memory V3: fix minor typo in comment (Timothy Arceri) Signed-off-by: Thomas Helland <[email protected]> Reviewed-by: Timothy Arceri <[email protected]>
Diffstat (limited to 'src')
-rw-r--r--src/mesa/program/hash_table.h66
1 files changed, 22 insertions, 44 deletions
diff --git a/src/mesa/program/hash_table.h b/src/mesa/program/hash_table.h
index 421d0e9dc5c..d75781869a3 100644
--- a/src/mesa/program/hash_table.h
+++ b/src/mesa/program/hash_table.h
@@ -111,8 +111,6 @@ static inline void *hash_table_find(struct hash_table *ht, const void *key)
* \warning
* The value passed by \c key is kept in the hash table and is used by later
* calls to \c hash_table_find.
- *
- * \sa hash_table_replace
*/
static inline void hash_table_insert(struct hash_table *ht, void *data,
const void *key)
@@ -121,33 +119,6 @@ static inline void hash_table_insert(struct hash_table *ht, void *data,
}
/**
- * Add an element to a hash table with replacement
- *
- * \return
- * 1 if it did replace the value (in which case the old key is kept), 0 if it
- * did not replace the value (in which case the new key is kept).
- *
- * \warning
- * If \c key is already in the hash table, \c data will \b replace the most
- * recently inserted \c data (see the warning in \c hash_table_insert) for
- * that key.
- *
- * \sa hash_table_insert
- */
-static inline bool hash_table_replace(struct hash_table *ht, void *data,
- const void *key)
-{
- struct hash_entry *entry = _mesa_hash_table_search(ht, key);
- if (entry) {
- entry->data = data;
- return true;
- } else {
- _mesa_hash_table_insert(ht, key, data);
- return false;
- }
-}
-
-/**
* Remove a specific element from a hash table.
*/
static inline void hash_table_remove(struct hash_table *ht, const void *key)
@@ -240,14 +211,14 @@ struct string_to_uint_map {
public:
string_to_uint_map()
{
- this->ht = hash_table_ctor(0, hash_table_string_hash,
- hash_table_string_compare);
+ this->ht = _mesa_hash_table_create(NULL, _mesa_key_hash_string,
+ _mesa_key_string_equal);
}
~string_to_uint_map()
{
hash_table_call_foreach(this->ht, delete_key, NULL);
- hash_table_dtor(this->ht);
+ _mesa_hash_table_destroy(this->ht, NULL);
}
/**
@@ -256,7 +227,7 @@ public:
void clear()
{
hash_table_call_foreach(this->ht, delete_key, NULL);
- hash_table_clear(this->ht);
+ _mesa_hash_table_clear(this->ht, NULL);
}
/**
@@ -290,12 +261,13 @@ public:
*/
bool get(unsigned &value, const char *key)
{
- const intptr_t v =
- (intptr_t) hash_table_find(this->ht, (const void *) key);
+ hash_entry *entry = _mesa_hash_table_search(this->ht,
+ (const void *) key);
- if (v == 0)
- return false;
+ if (!entry)
+ return false;
+ const intptr_t v = (intptr_t) entry->data;
value = (unsigned)(v - 1);
return true;
}
@@ -307,19 +279,25 @@ public:
* valid value in the table. Bias the value by +1 so that a
* user-specified zero is stored as 1. This enables ::get to tell the
* difference between a user-specified zero (returned as 1 by
- * hash_table_find) and the key not in the table (returned as 0 by
- * hash_table_find).
+ * _mesa_hash_table_search) and the key not in the table (returned as 0 by
+ * _mesa_hash_table_search).
*
* The net effect is that we can't store UINT_MAX in the table. This is
* because UINT_MAX+1 = 0.
*/
assert(value != UINT_MAX);
char *dup_key = strdup(key);
- bool result = hash_table_replace(this->ht,
- (void *) (intptr_t) (value + 1),
- dup_key);
- if (result)
- free(dup_key);
+
+ struct hash_entry *entry = _mesa_hash_table_search(this->ht, dup_key);
+ if (entry) {
+ entry->data = (void *) (intptr_t) (value + 1);
+ } else {
+ _mesa_hash_table_insert(this->ht, dup_key,
+ (void *) (intptr_t) (value + 1));
+ }
+
+ if (entry)
+ free(dup_key);
}
private: