This patch is Reviewed-by: Ian Romanick <ian.d.roman...@intel.com>
On 03/31/2016 05:04 PM, Dylan Baker wrote: > In python 2 range returns a new list, which is okay for very small > values, but can get quite expensive for larger lists. xrange on the > other hand is an iterator, which requires less memory and processing > power. > > Signed-off-by: Dylan Baker <dylanx.c.ba...@intel.com> > --- > src/mapi/glapi/gen/glX_proto_size.py | 2 +- > src/mapi/glapi/gen/glX_server_table.py | 16 ++++++++-------- > src/mapi/glapi/gen/gl_XML.py | 5 ++--- > src/mapi/glapi/gen/gl_apitemp.py | 2 +- > 4 files changed, 12 insertions(+), 13 deletions(-) > > diff --git a/src/mapi/glapi/gen/glX_proto_size.py > b/src/mapi/glapi/gen/glX_proto_size.py > index d8b9c21..0c0b106 100644 > --- a/src/mapi/glapi/gen/glX_proto_size.py > +++ b/src/mapi/glapi/gen/glX_proto_size.py > @@ -151,7 +151,7 @@ class glx_enum_function(object): > masked_enums = {} > masked_count = {} > > - for i in range(0, mask + 1): > + for i in xrange(0, mask + 1): > masked_enums[i] = "0" > masked_count[i] = 0 > > diff --git a/src/mapi/glapi/gen/glX_server_table.py > b/src/mapi/glapi/gen/glX_server_table.py > index d1a2bb9..6443a99 100644 > --- a/src/mapi/glapi/gen/glX_server_table.py > +++ b/src/mapi/glapi/gen/glX_server_table.py > @@ -35,7 +35,7 @@ import license > > > def log2(value): > - for i in range(0, 30): > + for i in xrange(0, 30): > p = 1 << i > if p >= value: > return i > @@ -46,7 +46,7 @@ def log2(value): > def round_down_to_power_of_two(n): > """Returns the nearest power-of-two less than or equal to n.""" > > - for i in range(30, 0, -1): > + for i in xrange(30, 0, -1): > p = 1 << i > if p <= n: > return p > @@ -95,17 +95,17 @@ class function_table: > next_opcode = min_opcode + (1 << remaining_bits) > empty_children = 0 > > - for M in range(0, remaining_bits): > + for M in xrange(0, remaining_bits): > op_count = 1 << (remaining_bits - M) > child_count = 1 << M > > empty_children = 0 > full_children = 0 > - for i in range(min_opcode, next_opcode, op_count): > + for i in xrange(min_opcode, next_opcode, op_count): > used = 0 > empty = 0 > > - for j in range(i, i + op_count): > + for j in xrange(i, i + op_count): > if j in self.functions: > used += 1 > else: > @@ -130,7 +130,7 @@ class function_table: > count = 1 > depth = 1 > all_children_are_nonempty_leaf_nodes = 1 > - for i in range(min_opcode, next_opcode, op_count): > + for i in xrange(min_opcode, next_opcode, op_count): > n = self.divide_group(i, total + M) > > if not (n[1] == [] and not self.is_empty_leaf(i, n[0])): > @@ -151,7 +151,7 @@ class function_table: > return [M, children, count, depth] > > def is_empty_leaf(self, base_opcode, M): > - for op in range(base_opcode, base_opcode + (1 << M)): > + for op in xrange(base_opcode, base_opcode + (1 << M)): > if op in self.functions: > return 0 > break > @@ -187,7 +187,7 @@ class function_table: > > print ' LEAF(%u),' % (len(self.lookup_table)) > > - for op in range(child_base_opcode, child_base_opcode + > (1 << child_M)): > + for op in xrange(child_base_opcode, child_base_opcode + > (1 << child_M)): > if op in self.functions: > func = self.functions[op] > size = func.command_fixed_length() > diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py > index de10019..695ef7f 100644 > --- a/src/mapi/glapi/gen/gl_XML.py > +++ b/src/mapi/glapi/gen/gl_XML.py > @@ -685,7 +685,7 @@ class gl_function(gl_item): > if len(parameters) != len(self.parameters): > raise RuntimeError("Parameter count mismatch in %s. Was %d, > now %d." % (name, len(self.parameters), len(parameters))) > > - for j in range(0, len(parameters)): > + for j in xrange(0, len(parameters)): > p1 = parameters[j] > p2 = self.parameters[j] > if not p1.compatible(p2): > @@ -975,9 +975,8 @@ class gl_api(object): > classify_category. Each iterated value is a tuple of the > name and number (which may be None) of the category. > """ > - > list = [] > - for cat_type in range(0,4): > + for cat_type in xrange(0,4): > keys = self.categories[cat_type].keys() > keys.sort() > > diff --git a/src/mapi/glapi/gen/gl_apitemp.py > b/src/mapi/glapi/gen/gl_apitemp.py > index feb5f8e..5143ae3 100644 > --- a/src/mapi/glapi/gen/gl_apitemp.py > +++ b/src/mapi/glapi/gen/gl_apitemp.py > @@ -196,7 +196,7 @@ class PrintGlOffsets(gl_XML.gl_print_base): > print ' * when someone tries to call a dynamically-registered' > print ' * extension function without a current rendering context.' > print ' */' > - for i in range(1, 100): > + for i in xrange(1, 100): > print ' TABLE_ENTRY(Unused),' > > print '};' > _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev