[Mesa-dev] [PATCH 6/6] util: Avoid computing hash twice in string_to_uint_map

Thomas Helland thomashelland90 at gmail.com
Mon May 22 18:55:45 UTC 2017


This is not a hot path, but when we have the functionality we
should take advantage of it.
---
 src/util/string_to_uint_map.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/util/string_to_uint_map.h b/src/util/string_to_uint_map.h
index e0533ec6ea..3248696e88 100644
--- a/src/util/string_to_uint_map.h
+++ b/src/util/string_to_uint_map.h
@@ -138,12 +138,15 @@ public:
       assert(value != UINT_MAX);
       char *dup_key = strdup(key);
 
-      struct hash_entry *entry = _mesa_hash_table_search(this->ht, dup_key);
+      uint32_t hash = ht->key_hash_function(dup_key);
+      struct hash_entry *entry =
+            _mesa_hash_table_search_pre_hashed(this->ht, hash, 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));
+         _mesa_hash_table_insert_pre_hashed(this->ht, hash, dup_key,
+                                            (void *) (intptr_t) (value + 1));
       }
 
       if (entry)
-- 
2.13.0



More information about the mesa-dev mailing list