}
static struct hash_entry *
-hash_table_insert(struct hash_table *ht, uint32_t hash,
- const void *key, void *data)
+hash_table_get_entry(struct hash_table *ht, uint32_t hash, const void *key)
{
struct hash_entry *available_entry = NULL;
*/
if (!entry_is_deleted(ht, entry) &&
entry->hash == hash &&
- ht->key_equals_function(key, entry->key)) {
- entry->key = key;
- entry->data = data;
+ ht->key_equals_function(key, entry->key))
return entry;
- }
hash_address += double_hash;
if (hash_address >= size)
if (entry_is_deleted(ht, available_entry))
ht->deleted_entries--;
available_entry->hash = hash;
- available_entry->key = key;
- available_entry->data = data;
ht->entries++;
return available_entry;
}
return NULL;
}
+static struct hash_entry *
+hash_table_insert(struct hash_table *ht, uint32_t hash,
+ const void *key, void *data)
+{
+ struct hash_entry *entry = hash_table_get_entry(ht, hash, key);
+
+ if (entry) {
+ entry->key = key;
+ entry->data = data;
+ }
+
+ return entry;
+}
+
/**
* Inserts the key with the given hash into the table.
*
return;
_key->value = key;
- _mesa_hash_table_insert(ht->table, _key, data);
+ struct hash_entry *entry =
+ hash_table_get_entry(ht->table, key_u64_hash(_key), _key);
+
+ if (!entry) {
+ FREE(_key);
+ return;
+ }
+
+ entry->data = data;
+ if (!entry_is_present(ht->table, entry))
+ entry->key = _key;
+ else
+ FREE(_key);
}
}