Since condition_list is an ordered list, we can just use enumerate() when walking through it to get (index, value) pairs, rather than storing a second dictionary mapping items to their indices. When looking for an existing entry, use list.index() to get the index of that item. --- src/glsl/nir/nir_algebraic.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
Here's my review feedback for this patch. I haven't tested it, but it does compile at least. With this squashed in, patches 1-2 of the miniseries are Reviewed-by: Kenneth Graunke <kenn...@whitecape.org> diff --git a/src/glsl/nir/nir_algebraic.py b/src/glsl/nir/nir_algebraic.py index 9c5a906..1acf1ce 100644 --- a/src/glsl/nir/nir_algebraic.py +++ b/src/glsl/nir/nir_algebraic.py @@ -128,7 +128,6 @@ class Expression(Value): _optimization_ids = itertools.count() -condition_index_map = {'true' : 0} condition_list = ['true'] class SearchAndReplace(object): @@ -142,12 +141,9 @@ class SearchAndReplace(object): else: self.condition = 'true' - if self.condition in condition_index_map: - self.condition_index = condition_index_map[self.condition] - else: - self.condition_index = len(condition_list) + if self.condition not in condition_list: condition_list.append(self.condition) - condition_index_map[self.condition] = self.condition_index + self.condition_index = condition_list.index(self.condition) varset = VarSet() if isinstance(search, Expression): @@ -250,8 +246,8 @@ ${pass_name}(nir_shader *shader) bool condition_flags[${len(condition_list)}]; const nir_shader_compiler_options *options = shader->options; - % for condition in condition_list: - condition_flags[${condition_index_map[condition]}] = ${condition}; + % for index, condition in enumerate(condition_list): + condition_flags[${index}] = ${condition}; % endfor nir_foreach_overload(shader, overload) { @@ -280,5 +276,4 @@ class AlgebraicPass(object): def render(self): return _algebraic_pass_template.render(pass_name=self.pass_name, xform_dict=self.xform_dict, - condition_list=condition_list, - condition_index_map=condition_index_map) + condition_list=condition_list) -- 2.2.2 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev