<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Feb 22, 2017 at 3:15 PM, Dylan Baker <span dir="ltr"><<a href="mailto:dylan@pnwbakers.com" target="_blank">dylan@pnwbakers.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">These are all fairly small cleanups/tweaks that don't really deserve<br>
their own patch.<br>
<br>
- Prefer comprehensions to map() and filter(), since they're faster<br>
- replace unused variables with _<br>
- Use 4 spaces of indent<br>
- drop semicolons from the end of lines<br>
- Don't use parens around if conditions<br>
- don't put spaces around brackets<br>
- don't import modules as caps (ET -> et)<br>
- Use docstrings instead of comments<br>
<br>
Signed-off-by: Dylan Baker <<a href="mailto:dylanx.c.baker@intel.com">dylanx.c.baker@intel.com</a>><br>
---<br>
src/intel/vulkan/anv_<wbr>entrypoints_gen.py | 63 ++++++++++++++++++------------<wbr>---<br>
1 file changed, 34 insertions(+), 29 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/anv_<wbr>entrypoints_gen.py b/src/intel/vulkan/anv_<wbr>entrypoints_gen.py<br>
index 3f7a1ce294..358cf1e1e2 100644<br>
--- a/src/intel/vulkan/anv_<wbr>entrypoints_gen.py<br>
+++ b/src/intel/vulkan/anv_<wbr>entrypoints_gen.py<br>
@@ -24,20 +24,20 @@<br>
<br>
import sys<br>
import textwrap<br>
-import xml.etree.ElementTree as ET<br>
+import xml.etree.ElementTree as et<br>
<br>
max_api_version = 1.0<br>
<br>
supported_extensions = [<br>
- 'VK_KHR_get_physical_device_<wbr>properties2',<br>
- 'VK_KHR_maintenance1',<br>
- 'VK_KHR_sampler_mirror_clamp_<wbr>to_edge',<br>
- 'VK_KHR_shader_draw_<wbr>parameters',<br>
- 'VK_KHR_surface',<br>
- 'VK_KHR_swapchain',<br>
- 'VK_KHR_wayland_surface',<br>
- 'VK_KHR_xcb_surface',<br>
- 'VK_KHR_xlib_surface',<br>
+ 'VK_KHR_get_physical_device_<wbr>properties2',<br>
+ 'VK_KHR_maintenance1',<br>
+ 'VK_KHR_sampler_mirror_clamp_<wbr>to_edge',<br>
+ 'VK_KHR_shader_draw_<wbr>parameters',<br>
+ 'VK_KHR_surface',<br>
+ 'VK_KHR_swapchain',<br>
+ 'VK_KHR_wayland_surface',<br>
+ 'VK_KHR_xcb_surface',<br>
+ 'VK_KHR_xlib_surface',<br>
]<br>
<br>
# We generate a static hash table for entry point lookup<br>
@@ -53,33 +53,37 @@ hash_mask = hash_size - 1<br>
prime_factor = 5024183<br>
prime_step = 19<br>
<br>
+opt_header = False<br>
+opt_code = False<br>
+<br>
+if sys.argv[1] == "header":<br>
+ opt_header = True<br>
+ sys.argv.pop()<br>
+elif sys.argv[1] == "code":<br>
+ opt_code = True<br>
+ sys.argv.pop()<br>
+<br>
+<br>
def hash(name):<br>
- h = 0;<br>
+ h = 0<br>
for c in name:<br>
h = (h * prime_factor + ord(c)) & u32_mask<br>
<br>
return h<br>
<br>
+<br>
def print_guard_start(guard):<br>
if guard is not None:<br>
print "#ifdef {0}".format(guard)<br>
<br>
+<br>
def print_guard_end(guard):<br>
if guard is not None:<br>
print "#endif // {0}".format(guard)<br>
<br>
-opt_header = False<br>
-opt_code = False<br>
<br>
-if (sys.argv[1] == "header"):<br>
- opt_header = True<br>
- sys.argv.pop()<br>
-elif (sys.argv[1] == "code"):<br>
- opt_code = True<br>
- sys.argv.pop()<br>
-<br>
-# Extract the entry points from the registry<br>
def get_entrypoints(doc, entrypoints_to_defines):<br>
+ """Extract the entry points from the registry."""<br>
entrypoints = []<br>
<br>
enabled_commands = set()<br>
@@ -108,7 +112,7 @@ def get_entrypoints(doc, entrypoints_to_defines):<br>
continue<br>
<br>
shortname = fullname[2:]<br>
- params = map(lambda p: "".join(p.itertext()), command.findall('./param'))<br>
+ params = (''.join(p.itertext()) for p in command.findall('./param'))<br>
params = ', '.join(params)<br>
if fullname in entrypoints_to_defines:<br>
guard = entrypoints_to_defines[<wbr>fullname]<br>
@@ -119,8 +123,9 @@ def get_entrypoints(doc, entrypoints_to_defines):<br>
<br>
return entrypoints<br>
<br>
-# Maps entry points to extension defines<br>
+<br>
def get_entrypoints_defines(doc):<br>
+ """Maps entry points to extension defines."""<br>
entrypoints_to_defines = {}<br>
extensions = doc.findall('./extensions/<wbr>extension')<br>
for extension in extensions:<br>
@@ -133,7 +138,7 @@ def get_entrypoints_defines(doc):<br>
<br>
<br>
def main():<br>
- doc = ET.parse(sys.stdin)<br>
+ doc = et.parse(sys.stdin)<br>
entrypoints = get_entrypoints(doc, get_entrypoints_defines(doc))<br>
<br>
# Manually add CreateDmaBufImageINTEL for which we don't have an extension<br>
@@ -225,7 +230,7 @@ def main():<br>
static const char strings[] =""")<br>
<br>
offsets = []<br>
- i = 0;<br>
+ i = 0<br>
for type, name, args, num, h, guard in entrypoints:<br>
print " \"vk%s\\0\"" % name<br>
offsets.append(i)<br>
@@ -247,7 +252,7 @@ def main():<br>
*/<br>
""")<br>
<br>
- for layer in [ "anv", "gen7", "gen75", "gen8", "gen9" ]:<br>
+ for layer in ["anv", "gen7", "gen75", "gen8", "gen9"]:<br>
for type, name, args, num, h, guard in entrypoints:<br>
print_guard_start(guard)<br>
print "%s %s_%s(%s) __attribute__ ((weak));" % (type, layer, name, args)<br>
@@ -295,8 +300,8 @@ def main():<br>
# uint16_t table of entry point indices. We use 0xffff to indicate an entry<br>
# in the hash table is empty.<br>
<br>
- map = [none for f in xrange(hash_size)]<br>
- collisions = [0 for f in xrange(10)]<br>
+ map = [none for _ in xrange(hash_size)]<br>
+ collisions = [0 for _ in xrange(10)]<br></blockquote><div><br></div><div>Aren't these just "[none] * hash_size" and "[0] * 10"?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
for type, name, args, num, h, guard in entrypoints:<br>
level = 0<br>
while map[h & hash_mask] != none:<br>
@@ -312,7 +317,7 @@ def main():<br>
print " * size %d entries" % hash_size<br>
print " * collisions entries"<br>
for i in xrange(10):<br>
- if (i == 9):<br>
+ if i == 9:<br>
plus = "+"<br>
else:<br>
plus = " "<br>
<span class="HOEnZb"><font color="#888888">--<br>
2.11.1<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>