<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Sep 21, 2017 at 10:34 AM, 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">Quoting Jason Ekstrand (2017-09-21 08:32:22)<br>
<div><div class="h5">> While using iterparse is potentially a little more efficient, the Vulkan<br>
> registry XML is not large and using regular element tree simplifies the<br>
> parsing logic substantially.<br>
> ---<br>
>  src/vulkan/util/gen_enum_to_<wbr>str.py | 41 +++++++++++++++---------------<wbr>--------<br>
>  1 file changed, 16 insertions(+), 25 deletions(-)<br>
><br>
> diff --git a/src/vulkan/util/gen_enum_to_<wbr>str.py b/src/vulkan/util/gen_enum_to_<wbr>str.py<br>
> index 8f32102..e5f8964 100644<br>
> --- a/src/vulkan/util/gen_enum_to_<wbr>str.py<br>
> +++ b/src/vulkan/util/gen_enum_to_<wbr>str.py<br>
> @@ -157,31 +157,22 @@ def parse_xml(enum_factory, ext_factory, filename):<br>
>      of VkEnum objects.<br>
>      """<br>
><br>
> -    with open(filename, 'rb') as f:<br>
> -        context = iter(et.iterparse(f, events=('start', 'end')))<br>
> -<br>
> -        # This gives the root element, since goal is to iterate over the<br>
> -        # elements without building a tree, this allows the root to be cleared<br>
> -        # (erase the elements) after the children have been processed.<br>
> -        _, root = next(context)<br>
> -<br>
> -        for event, elem in context:<br>
> -            if event == 'end' and elem.tag == 'enums':<br>
> -                type_ = elem.attrib.get('type')<br>
> -                if type_ == 'enum':<br>
> -                    enum = enum_factory(elem.attrib['<wbr>name'])<br>
> -                    enum.values.extend([e.attrib['<wbr>name'] for e in elem<br>
> -                                        if e.tag == 'enum'])<br>
> -            elif event == 'start' and elem.tag == 'extension':<br>
> -                ext_factory(elem.attrib['name'<wbr>], int(elem.attrib['number']))<br>
> -            elif event == 'end' and elem.tag == 'extension':<br>
> -                if elem.attrib['supported'] != 'vulkan':<br>
> -                    continue<br>
> -                for e in elem.findall('.//enum[@<wbr>extends][@offset]'):<br>
> -                    enum = enum_factory(e.attrib['<wbr>extends'])<br>
> -                    enum.values.append(e.attrib['<wbr>name'],)<br>
> -<br>
> -            root.clear()<br>
> +    xml = et.parse(filename)<br>
> +<br>
> +    for enum_type in xml.findall('./enums'):<br>
> +        if enum_type.attrib.get('type') != 'enum':<br>
> +            continue<br>
<br>
</div></div>please do not use continue for iterating xlm. xpath is more than capable of<br>
representing this in less code, and it's implemented in C so it will be much<br>
faster.<br>
<br>
for enum_type in xml.findall('./enums[@type="<wbr>enum"]')<span class=""><br></span></blockquote><div><br></div><div>Done.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
> +<br>
> +        enum = enum_factory(enum_type.attrib[<wbr>'name'])<br>
> +        for value in enum_type.findall('./enum'):<br>
> +            enum.values.append(value.<wbr>attrib['name'])<br>
> +<br>
> +    for ext_elem in xml.findall('./extension'):<br>
> +        if ext_elem.attrib['supported'] != 'vulkan':<br>
> +            continue<br>
<br>
</span>please do the same thing here.<span class=""><br></span></blockquote><div><br></div><div>Done.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
> +<br>
> +        ext_factory(ext_elem.attrib['<wbr>name'],<br>
> +                    int(ext_elem.attrib['number'])<wbr>)<br>
><br>
>  def main():<br>
>      parser = argparse.ArgumentParser()<br>
> --<br>
> 2.5.0.400.gff86faf<br>
><br>
</span>> ______________________________<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>
</blockquote></div><br></div></div>