From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVjFL-0004Su-9z for qemu-devel@nongnu.org; Tue, 16 Feb 2016 12:17:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aVjFG-0001hl-BQ for qemu-devel@nongnu.org; Tue, 16 Feb 2016 12:17:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55691) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aVjFG-0001hg-4Q for qemu-devel@nongnu.org; Tue, 16 Feb 2016 12:17:02 -0500 References: <1455582057-27565-1-git-send-email-eblake@redhat.com> <1455582057-27565-6-git-send-email-eblake@redhat.com> <87bn7gpqf9.fsf@blackfin.pond.sub.org> From: Eric Blake Message-ID: <56C3598D.5000203@redhat.com> Date: Tue, 16 Feb 2016 10:17:01 -0700 MIME-Version: 1.0 In-Reply-To: <87bn7gpqf9.fsf@blackfin.pond.sub.org> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="weCbdNf3CNmFqnHMs7HCe8x9sF2PcQXJG" Subject: Re: [Qemu-devel] [PATCH v10 05/13] qapi-visit: Simplify how we visit common union members List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: qemu-devel@nongnu.org, Michael Roth This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --weCbdNf3CNmFqnHMs7HCe8x9sF2PcQXJG Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 02/16/2016 09:31 AM, Markus Armbruster wrote: > Eric Blake writes: >=20 >> From: Markus Armbruster >> >> 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 =3D NULL; >> + >> + visit_type_KeyValueKind(v, "type", &(*obj)->type, &err); >> + error_propagate(errp, err); >> +} >> + This is one of the places that is several lines longer if we always emit the goto and label. If we drop 3 and 4, then the commit message needs a rebase. >> void visit_type_KeyValue(Visitor *v, const char *name, KeyValue *= *obj, Error **errp) >> { >> Error *err =3D 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 =3D NULL; >> + >> + visit_type_CpuInfoBase_fields(v, (CpuInfoBase **)obj, &err); >> + error_propagate(errp, err); >> +} And another beneficiary of the omitted goto that gets longer. >> + >> 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 >> Message-Id: <1453902888-20457-2-git-send-email-armbru@redhat.com> >> [rebase to avoid pointless gotos in new code] >=20 > Also: examples in commit message replaced by better ones :) I picked the shortest names possible, to minimize the length of the commit message, and favoring qapi-schema.json over the testsuite. You noticed :) >=20 >> Signed-off-by: Eric Blake >=20 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --weCbdNf3CNmFqnHMs7HCe8x9sF2PcQXJG Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWw1mNAAoJEKeha0olJ0NqJLUIAK4a3QO8DSK18Czj22mmHSb4 /7U96stiiKKPT+ukaV5FqdoRgZKZIejmBtiTFBXXKwRgUTSjKNEIaqBf/qlK0Mtr Dqm2xcbWzmr/EmevlrHviX5gDISxwXNokBXKescvjnBG/Ub94EN/qR24QD+HZB9F SEVXoFZnBaGpXOL6hxipxEyhXsem+cvquP35ik3FSoeHxg613JC4dD4DdNesm9TT Tu7FTuJXk+shUQL6B6IAAKrXcgq+aAOjlrM6FBqV8XnlLRSvD2wabi2D484Mmmb1 e2JUQWaOXikvSA8QS/AeaMIhXDp6v3Ps5R9mk6ebdwrmgyK6NeSMAp3vJhj6D7Q= =PjGs -----END PGP SIGNATURE----- --weCbdNf3CNmFqnHMs7HCe8x9sF2PcQXJG--