[Mesa-dev] [PATCH 1/7] mesa: Avoid unnecessary string hashing in symbol table

Thomas Helland thomashelland90 at gmail.com
Thu Feb 2 20:57:27 UTC 2017


This is one of our largest users of hash_table_insert. This causes some
code duplication and a parameter to pass in, so might not be worth it.
---
 src/mesa/program/symbol_table.c | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/mesa/program/symbol_table.c b/src/mesa/program/symbol_table.c
index 37066c904c..bf366035b1 100644
--- a/src/mesa/program/symbol_table.c
+++ b/src/mesa/program/symbol_table.c
@@ -129,9 +129,10 @@ _mesa_symbol_table_push_scope(struct _mesa_symbol_table *table)
 
 
 static struct symbol *
-find_symbol(struct _mesa_symbol_table *table, const char *name)
+find_symbol(struct _mesa_symbol_table *table, uint32_t hash, const char *name)
 {
-   struct hash_entry *entry = _mesa_hash_table_search(table->ht, name);
+   struct hash_entry *entry =
+         _mesa_hash_table_search_pre_hashed(table->ht, hash, name);
    return entry ? (struct symbol *) entry->data : NULL;
 }
 
@@ -148,7 +149,8 @@ int
 _mesa_symbol_table_symbol_scope(struct _mesa_symbol_table *table,
                                 const char *name)
 {
-   struct symbol *const sym = find_symbol(table, name);
+   uint32_t hash = table->ht->key_hash_function(name);
+   struct symbol *const sym = find_symbol(table, hash, name);
 
    if (sym) {
       assert(sym->depth <= table->depth);
@@ -163,7 +165,8 @@ void *
 _mesa_symbol_table_find_symbol(struct _mesa_symbol_table *table,
                                const char *name)
 {
-   struct symbol *const sym = find_symbol(table, name);
+   uint32_t hash = table->ht->key_hash_function(name);
+   struct symbol *const sym = find_symbol(table, hash, name);
    if (sym)
       return sym->data;
 
@@ -175,8 +178,9 @@ int
 _mesa_symbol_table_add_symbol(struct _mesa_symbol_table *table,
                               const char *name, void *declaration)
 {
+   uint32_t hash = table->ht->key_hash_function(name);
    struct symbol *new_sym;
-   struct symbol *sym = find_symbol(table, name);
+   struct symbol *sym = find_symbol(table, hash, name);
 
    if (sym && sym->depth == table->depth)
       return -1;
@@ -206,7 +210,8 @@ _mesa_symbol_table_add_symbol(struct _mesa_symbol_table *table,
 
    table->current_scope->symbols = new_sym;
 
-   _mesa_hash_table_insert(table->ht, new_sym->name, new_sym);
+   _mesa_hash_table_insert_pre_hashed(table->ht, hash, new_sym->name,
+                                      new_sym);
 
    return 0;
 }
@@ -230,9 +235,10 @@ int
 _mesa_symbol_table_add_global_symbol(struct _mesa_symbol_table *table,
                                      const char *name, void *declaration)
 {
+   uint32_t hash = table->ht->key_hash_function(name);
    struct scope_level *top_scope;
    struct symbol *inner_sym = NULL;
-   struct symbol *sym = find_symbol(table, name);
+   struct symbol *sym = find_symbol(table, hash, name);
 
    while (sym) {
       if (sym->depth == 0)
-- 
2.11.0



More information about the mesa-dev mailing list