diff options
| author | Philipp Hahn <hahn@univention.de> | 2018-11-20 11:29:12 +0100 |
|---|---|---|
| committer | Jano Tomko <jtomko@redhat.com> | 2020-09-01 13:26:01 +0000 |
| commit | 659d0b4dfdcefc52fc67d4486b1aed4212bc6dcf (patch) | |
| tree | 469f958b9f2cc7cc17ca945bd6a06e5ea4962ea6 | |
| parent | a0798b9bbcb22ec3deebd14387f29dda91d2dbb3 (diff) | |
| download | libvirt-python-659d0b4dfdcefc52fc67d4486b1aed4212bc6dcf.tar.gz | |
generator: Check contained in hash
directly instead of explicitly requesting only the keys as a list and
converting that list to another list.
Checking directly for an element to be contained in a hash is much more
efficient as this is done using hashing O(1) instead of walking the list
in half on average O(n).
Signed-off-by: Philipp Hahn <hahn@univention.de>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
| -rwxr-xr-x | generator.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/generator.py b/generator.py index ed9b1c2..6ab64c6 100755 --- a/generator.py +++ b/generator.py @@ -95,11 +95,11 @@ class docParser(xml.sax.handler.ContentHandler): self.function_return = None self.function_file = None self.function_module = None - if 'name' in attrs.keys(): + if 'name' in attrs: self.function = attrs['name'] - if 'file' in attrs.keys(): + if 'file' in attrs: self.function_file = attrs['file'] - if 'module' in attrs.keys(): + if 'module' in attrs: self.function_module = attrs['module'] elif tag == 'cond': self._data = [] @@ -110,24 +110,24 @@ class docParser(xml.sax.handler.ContentHandler): self.function_arg_name = None self.function_arg_type = None self.function_arg_info = None - if 'name' in attrs.keys(): + if 'name' in attrs: self.function_arg_name = attrs['name'] if self.function_arg_name == 'from': self.function_arg_name = 'frm' - if 'type' in attrs.keys(): + if 'type' in attrs: self.function_arg_type = attrs['type'] - if 'info' in attrs.keys(): + if 'info' in attrs: self.function_arg_info = attrs['info'] elif tag == 'return': if self.in_function == 1: self.function_return_type = None self.function_return_info = None self.function_return_field = None - if 'type' in attrs.keys(): + if 'type' in attrs: self.function_return_type = attrs['type'] - if 'info' in attrs.keys(): + if 'info' in attrs: self.function_return_info = attrs['info'] - if 'field' in attrs.keys(): + if 'field' in attrs: self.function_return_field = attrs['field'] elif tag == 'enum': # enums come from header files, hence virterror.h @@ -138,7 +138,7 @@ class docParser(xml.sax.handler.ContentHandler): elif attrs['file'] == "libvirt-qemu": qemu_enum(attrs['type'], attrs['name'], attrs['value']) elif tag == "macro": - if "string" in attrs.keys(): + if "string" in attrs: params.append((attrs['name'], attrs['string'])) def end(self, tag): |
