[Mesa-dev] [PATCH 5/6] vulkan: enum generator: Stop using iterparse
Dylan Baker
dylan at pnwbakers.com
Thu Sep 21 17:34:18 UTC 2017
Quoting Jason Ekstrand (2017-09-21 08:32:22)
> While using iterparse is potentially a little more efficient, the Vulkan
> registry XML is not large and using regular element tree simplifies the
> parsing logic substantially.
> ---
> src/vulkan/util/gen_enum_to_str.py | 41 +++++++++++++++-----------------------
> 1 file changed, 16 insertions(+), 25 deletions(-)
>
> diff --git a/src/vulkan/util/gen_enum_to_str.py b/src/vulkan/util/gen_enum_to_str.py
> index 8f32102..e5f8964 100644
> --- a/src/vulkan/util/gen_enum_to_str.py
> +++ b/src/vulkan/util/gen_enum_to_str.py
> @@ -157,31 +157,22 @@ def parse_xml(enum_factory, ext_factory, filename):
> of VkEnum objects.
> """
>
> - with open(filename, 'rb') as f:
> - context = iter(et.iterparse(f, events=('start', 'end')))
> -
> - # This gives the root element, since goal is to iterate over the
> - # elements without building a tree, this allows the root to be cleared
> - # (erase the elements) after the children have been processed.
> - _, root = next(context)
> -
> - for event, elem in context:
> - if event == 'end' and elem.tag == 'enums':
> - type_ = elem.attrib.get('type')
> - if type_ == 'enum':
> - enum = enum_factory(elem.attrib['name'])
> - enum.values.extend([e.attrib['name'] for e in elem
> - if e.tag == 'enum'])
> - elif event == 'start' and elem.tag == 'extension':
> - ext_factory(elem.attrib['name'], int(elem.attrib['number']))
> - elif event == 'end' and elem.tag == 'extension':
> - if elem.attrib['supported'] != 'vulkan':
> - continue
> - for e in elem.findall('.//enum[@extends][@offset]'):
> - enum = enum_factory(e.attrib['extends'])
> - enum.values.append(e.attrib['name'],)
> -
> - root.clear()
> + xml = et.parse(filename)
> +
> + for enum_type in xml.findall('./enums'):
> + if enum_type.attrib.get('type') != 'enum':
> + continue
please do not use continue for iterating xlm. xpath is more than capable of
representing this in less code, and it's implemented in C so it will be much
faster.
for enum_type in xml.findall('./enums[@type="enum"]')
> +
> + enum = enum_factory(enum_type.attrib['name'])
> + for value in enum_type.findall('./enum'):
> + enum.values.append(value.attrib['name'])
> +
> + for ext_elem in xml.findall('./extension'):
> + if ext_elem.attrib['supported'] != 'vulkan':
> + continue
please do the same thing here.
> +
> + ext_factory(ext_elem.attrib['name'],
> + int(ext_elem.attrib['number']))
>
> def main():
> parser = argparse.ArgumentParser()
> --
> 2.5.0.400.gff86faf
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20170921/06b751ce/attachment.sig>
More information about the mesa-dev
mailing list