[Mesa-dev] [PATCH 8/9] glsl: Make ir_variable_refcount use a hash table.
Eric Anholt
eric at anholt.net
Fri Mar 11 16:06:52 PST 2011
---
src/glsl/ir_variable_refcount.cpp | 19 +++++++++++++------
src/glsl/ir_variable_refcount.h | 9 +++++++--
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/src/glsl/ir_variable_refcount.cpp b/src/glsl/ir_variable_refcount.cpp
index 7d39abb..1bd3a60 100644
--- a/src/glsl/ir_variable_refcount.cpp
+++ b/src/glsl/ir_variable_refcount.cpp
@@ -49,16 +49,23 @@ variable_entry::variable_entry(ir_variable *var)
variable_entry *
ir_variable_refcount_visitor::get_variable_entry(ir_variable *var)
{
+ variable_entry *entry;
+
assert(var);
- foreach_iter(exec_list_iterator, iter, this->variable_list) {
- variable_entry *entry = (variable_entry *)iter.get();
- if (entry->var == var)
- return entry;
+
+ if (!this->ht) {
+ this->ht = hash_table_ctor(0, hash_table_pointer_hash,
+ hash_table_pointer_compare);
}
- variable_entry *entry = new(mem_ctx) variable_entry(var);
- assert(entry->referenced_count == 0);
+ entry = (variable_entry *)hash_table_find(this->ht, var);
+ if (entry)
+ return entry;
+
+ entry = new(mem_ctx) variable_entry(var);
+ hash_table_insert(this->ht, entry, var);
this->variable_list.push_tail(entry);
+
return entry;
}
diff --git a/src/glsl/ir_variable_refcount.h b/src/glsl/ir_variable_refcount.h
index 906135a..e5c7aeb 100644
--- a/src/glsl/ir_variable_refcount.h
+++ b/src/glsl/ir_variable_refcount.h
@@ -32,6 +32,7 @@
#include "ir.h"
#include "ir_visitor.h"
#include "glsl_types.h"
+#include "program/hash_table.h"
class variable_entry : public exec_node
{
@@ -55,11 +56,15 @@ public:
ir_variable_refcount_visitor(void)
{
this->mem_ctx = ralloc_context(NULL);
+ this->ht = NULL;
this->variable_list.make_empty();
}
~ir_variable_refcount_visitor(void)
{
+ if (this->ht)
+ hash_table_dtor(this->ht);
+
ralloc_free(this->mem_ctx);
}
@@ -71,8 +76,8 @@ public:
variable_entry *get_variable_entry(ir_variable *var);
- /* List of variable_entry */
- exec_list variable_list;
+ exec_list variable_list; /* List of variable_entry */
+ struct hash_table *ht; /* Mapping of ir_variable to variable_entry */
void *mem_ctx;
};
--
1.7.4.1
More information about the mesa-dev
mailing list