[Top][All Lists]

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

Re: [Qemu-devel] [PATCH 1/3] qapi-visit: Simplify how we visit common un

From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH 1/3] qapi-visit: Simplify how we visit common union members
Date: Wed, 27 Jan 2016 14:48:24 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.0

On 01/27/2016 06:54 AM, Markus Armbruster wrote:
> For a simple union SU, gen_visit_union() generates a visit of its
> single tag member, like this:
>     visit_type_SUKind(v, "type", &(*obj)->type, &err);
> For a flat union FU with base B, it generates a visit of its base
> fields:
>     visit_type_B_fields(v, (B **)obj, &err);
> Instead, we can simply visit the common members using the same fields
> visit function we use for structs, generated with
> gen_visit_struct_fields().  This function visits the base if any, then
> the local members.

I like how you've split up my gen_struct/gen_union merge into a few more
steps. I'll be incorporating your patch into my v10 spin.

> For a simple union SU, visit_type_SU_fields() contains exactly the old
> tag member visit, because there is no base, and the tag member is the
> only member.  For instance, the code generated for
> qapi-schema-test.json's UserDefNativeListUnion changes like this:
>     @@ -740,6 +766,19 @@ out:
>        error_propagate(errp, err);
>      }
>     +static void visit_type_UserDefNativeListUnion_fields(Visitor *v, 
> UserDefNativeListUnion **obj, Error **errp)

I may try to rewrite the commit to pick a shorter example, though :)

> As you see, the generated code grows a bit, but in practice, it's lost
> in the noise: qapi-schema.json's qapi-visit.c gains roughly 1%.
> This simplification became possible with commit 441cbac "qapi-visit:
> Convert to QAPISchemaVisitor, fixing bugs".  It's a step towards
> unifying gen_struct() and gen_union().
> Signed-off-by: Markus Armbruster <address@hidden>
> ---
>  scripts/qapi-visit.py | 27 ++++-----------------------
>  1 file changed, 4 insertions(+), 23 deletions(-)

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]