python: Better iterate over dictionaries
In Python 2, dictionaries have 2 sets of methods to iterate over their keys and values: keys()/values()/items() and iterkeys()/itervalues()/iteritems(). The former return lists while the latter return iterators. Python 3 dropped the method which return lists, and renamed the methods returning iterators to keys()/values()/items(). Using those names makes the scripts compatible with both Python 2 and 3. Signed-off-by: Mathieu Bridon <bochecha@daitauha.fr> Reviewed-by: Eric Engestrom <eric.engestrom@intel.com> Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
This commit is contained in:
committed by
Dylan Baker
parent
fdf946ffbf
commit
5530cb1296
@@ -834,7 +834,7 @@ class gl_function( gl_item ):
|
||||
versions.
|
||||
"""
|
||||
result = []
|
||||
for entry_point, api_to_ver in self.entry_point_api_map.iteritems():
|
||||
for entry_point, api_to_ver in self.entry_point_api_map.items():
|
||||
if api not in api_to_ver:
|
||||
continue
|
||||
if version is not None and version < api_to_ver[api]:
|
||||
@@ -881,7 +881,7 @@ class gl_api(object):
|
||||
def filter_functions(self, entry_point_list):
|
||||
"""Filter out entry points not in entry_point_list."""
|
||||
functions_by_name = {}
|
||||
for func in self.functions_by_name.itervalues():
|
||||
for func in self.functions_by_name.values():
|
||||
entry_points = [ent for ent in func.entry_points if ent in entry_point_list]
|
||||
if entry_points:
|
||||
func.filter_entry_points(entry_points)
|
||||
@@ -894,7 +894,7 @@ class gl_api(object):
|
||||
optionally, not in the given version of the given API).
|
||||
"""
|
||||
functions_by_name = {}
|
||||
for func in self.functions_by_name.itervalues():
|
||||
for func in self.functions_by_name.values():
|
||||
entry_points = func.entry_points_for_api_version(api, version)
|
||||
if entry_points:
|
||||
func.filter_entry_points(entry_points)
|
||||
@@ -1003,13 +1003,13 @@ class gl_api(object):
|
||||
|
||||
def functionIterateByOffset(self):
|
||||
max_offset = -1
|
||||
for func in self.functions_by_name.itervalues():
|
||||
for func in self.functions_by_name.values():
|
||||
if func.offset > max_offset:
|
||||
max_offset = func.offset
|
||||
|
||||
|
||||
temp = [None for i in range(0, max_offset + 1)]
|
||||
for func in self.functions_by_name.itervalues():
|
||||
for func in self.functions_by_name.values():
|
||||
if func.offset != -1:
|
||||
temp[ func.offset ] = func
|
||||
|
||||
@@ -1023,7 +1023,7 @@ class gl_api(object):
|
||||
|
||||
|
||||
def functionIterateAll(self):
|
||||
return self.functions_by_name.itervalues()
|
||||
return self.functions_by_name.values()
|
||||
|
||||
|
||||
def enumIterateByName(self):
|
||||
@@ -1064,7 +1064,7 @@ class gl_api(object):
|
||||
|
||||
|
||||
def typeIterate(self):
|
||||
return self.types_by_name.itervalues()
|
||||
return self.types_by_name.values()
|
||||
|
||||
|
||||
def find_type( self, type_name ):
|
||||
|
||||
@@ -202,13 +202,13 @@ class PrintCode(gl_XML.gl_print_base):
|
||||
|
||||
# Determine how many functions have a defined offset.
|
||||
func_count = 0
|
||||
for f in api.functions_by_name.itervalues():
|
||||
for f in api.functions_by_name.values():
|
||||
if f.offset != -1:
|
||||
func_count += 1
|
||||
|
||||
# Build the mapping from offset to function name.
|
||||
funcnames = [None] * func_count
|
||||
for f in api.functions_by_name.itervalues():
|
||||
for f in api.functions_by_name.values():
|
||||
if f.offset != -1:
|
||||
if not (funcnames[f.offset] is None):
|
||||
raise Exception("Function table has more than one function with same offset (offset %d, func %s)" % (f.offset, f.name))
|
||||
|
||||
Reference in New Issue
Block a user