qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH for-2.9 42/47] qapi: enum_types is a list used l


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH for-2.9 42/47] qapi: enum_types is a list used like a dict, make it one
Date: Tue, 14 Mar 2017 19:47:26 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 03/13/2017 01:18 AM, Markus Armbruster wrote:
> Signed-off-by: Markus Armbruster <address@hidden>
> ---
>  scripts/qapi.py | 29 ++++++-----------------------
>  1 file changed, 6 insertions(+), 23 deletions(-)
> 

Reviewed-by: Eric Blake <address@hidden>

No idea if python actually behaves more efficiently, but this is a nice
algorithmic change:

> diff --git a/scripts/qapi.py b/scripts/qapi.py
> index f06e3c4..5a3a606 100644
> --- a/scripts/qapi.py
> +++ b/scripts/qapi.py
> @@ -46,7 +46,7 @@ returns_whitelist = []
>  # Whitelist of entities allowed to violate case conventions
>  name_case_whitelist = []
>  
> -enum_types = []
> +enum_types = {}
>  struct_types = []
>  union_types = []
>  all_names = {}
> @@ -562,7 +562,7 @@ def find_alternate_member_qtype(qapi_type):
>          return builtin_types[qapi_type]
>      elif find_struct(qapi_type):
>          return 'QTYPE_QDICT'
> -    elif find_enum(qapi_type):
> +    elif qapi_type in enum_types:

A good dictionary uses a tree structure for O(log n), or even hash
lookup for amortized O(1) behavior here,

> -def find_enum(name):
> -    global enum_types
> -    for enum in enum_types:
> -        if enum['enum'] == name:
> -            return enum
> -    return None
> -

while our lookup was O(n) on paper.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]