Module: Mesa
Branch: main
Commit: 00b9685d966c8abeadd58102850f5b26f133b10f
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=00b9685d966c8abeadd58102850f5b26f133b10f

Author: Emma Anholt <[email protected]>
Date:   Wed Apr 12 12:13:24 2023 -0700

symbol_table: Prehash the key on insert, and reuse the entry on shadowing.

Mostly saves computing the hash twice, but while we're here there's no
need for shadowing to walk the table again.

Release Mesa build runtime of
KHR-Single-GL46.arrays_of_arrays_gl.SizedDeclarationsPrimitive -4.19869%
+/- 3.20231%

Reviewed-by: Alyssa Rosenzweig <[email protected]>
Reviewed-by: Marek Olšák <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22451>

---

 src/mesa/program/symbol_table.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/mesa/program/symbol_table.c b/src/mesa/program/symbol_table.c
index e988af25a22..834baf86b8d 100644
--- a/src/mesa/program/symbol_table.c
+++ b/src/mesa/program/symbol_table.c
@@ -176,7 +176,9 @@ _mesa_symbol_table_add_symbol(struct _mesa_symbol_table 
*table,
                               const char *name, void *declaration)
 {
    struct symbol *new_sym;
-   struct symbol *sym = find_symbol(table, name);
+   uint32_t hash = _mesa_hash_string(name);
+   struct hash_entry *entry = _mesa_hash_table_search_pre_hashed(table->ht, 
hash, name);
+   struct symbol *sym = entry ? entry->data : NULL;
 
    if (sym && sym->depth == table->depth)
       return -1;
@@ -191,9 +193,13 @@ _mesa_symbol_table_add_symbol(struct _mesa_symbol_table 
*table,
       /* Store link to symbol in outer scope with the same name */
       new_sym->next_with_same_name = sym;
       new_sym->name = sym->name;
+
+      entry->data = new_sym;
    } else {
       new_sym->name = (char *)(new_sym + 1);
       strcpy(new_sym->name, name);
+
+      _mesa_hash_table_insert_pre_hashed(table->ht, hash, new_sym->name, 
new_sym);
    }
 
    new_sym->next_with_same_scope = table->current_scope->symbols;
@@ -202,8 +208,6 @@ _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);
-
    return 0;
 }
 

Reply via email to