qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v11 05/15] qapi-visit: Simplify how we visit com


From: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH v11 05/15] qapi-visit: Simplify how we visit common union members
Date: Thu, 18 Feb 2016 13:16:46 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

Eric Blake <address@hidden> writes:

> From: Markus Armbruster <address@hidden>
>
> 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.
>
> 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.json's
> KeyValue changes like this:
>
>     +static void visit_type_KeyValue_fields(Visitor *v, KeyValue **obj, Error 
> **errp)
>     +{
>     +    Error *err = NULL;
>     +
>     +    visit_type_KeyValueKind(v, "type", &(*obj)->type, &err);
>     +    if (err) {
>     +        goto out;
>     +    }
>     +
>     +out:
>     +    error_propagate(errp, err);
>     +}
>     +
>      void visit_type_KeyValue(Visitor *v, const char *name, KeyValue **obj, 
> Error **errp)
>      {
>          Error *err = NULL;
>     @@ -4863,7 +4911,7 @@ void visit_type_KeyValue(Visitor *v, con
>          if (!*obj) {
>              goto out_obj;
>          }
>     -    visit_type_KeyValueKind(v, "type", &(*obj)->type, &err);
>     +    visit_type_KeyValue_fields(v, obj, &err);
>          if (err) {
>              goto out_obj;
>          }
>
> For a flat union FU, visit_type_FU_fields() contains exactly the old
> base fields visit, because there is a base, but no members.  For
> instance, the code generated for qapi-schema.json's CpuInfo changes
> like this:
>
>      static void visit_type_CpuInfoBase_fields(Visitor *v, CpuInfoBase **obj, 
> Error **errp);
>
>     +static void visit_type_CpuInfo_fields(Visitor *v, CpuInfo **obj, Error 
> **errp)
>     +{
>     +    Error *err = NULL;
>     +
>     +    visit_type_CpuInfoBase_fields(v, (CpuInfoBase **)obj, &err);
>     +    if (err) {
>     +        goto out;
>     +    }
>     +
>     +out:
>     +    error_propagate(errp, err);
>     +}
>     +
>      static void visit_type_CpuInfoX86_fields(Visitor *v, CpuInfoX86 **obj, 
> Error **errp)
> ...
>     @@ -3485,7 +3509,7 @@ void visit_type_CpuInfo(Visitor *v, cons
>          if (!*obj) {
>              goto out_obj;
>          }
>     -    visit_type_CpuInfoBase_fields(v, (CpuInfoBase **)obj, &err);
>     +    visit_type_CpuInfo_fields(v, obj, &err);
>          if (err) {
>              goto out_obj;
>          }
>
> 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>
> Message-Id: <address@hidden>
> [rebase, improve commit message example]
> Signed-off-by: Eric Blake <address@hidden>

v10 had a noteworthy rebase, but v11 is the original patch again, with
only the line numbers shifted a bit.  Suggest to drop "rebase, ".



reply via email to

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