[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v11 09/15] qapi: Adjust layout of FooList types
From: |
Markus Armbruster |
Subject: |
Re: [Qemu-devel] [PATCH v11 09/15] qapi: Adjust layout of FooList types |
Date: |
Thu, 18 Feb 2016 16:55:17 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) |
Eric Blake <address@hidden> writes:
> By sticking the next pointer first, we don't need a union with
> 64-bit padding for smaller types. On 32-bit platforms, this
> can reduce the size of uint8List from 16 bytes (or 12, depending
> on whether 64-bit ints can tolerate 4-byte alignment) down to 8.
> It has no effect on 64-bit platforms (where alignment still
> dictates a 16-byte struct); but fewer anonymous unions is still
> a win in my book.
>
> It requires visit_next_list() to gain a size parameter, to know
> what size element to allocate; comparable to the size parameter
> of visit_start_struct().
>
> I debated about going one step further, to allow for fewer casts,
> by doing:
> typedef GenericList GenericList;
> struct GenericList {
> GenericList *next;
> };
> struct FooList {
> GenericList base;
> Foo *value;
> };
> so that you convert to 'GenericList *' by '&foolist->base', and
> back by 'container_of(generic, GenericList, base)' (as opposed to
> the existing '(GenericList *)foolist' and '(FooList *)generic').
> But doing that would require hoisting the declaration of
> GenericList prior to inclusion of qapi-types.h, rather than its
> current spot in visitor.h; it also makes iteration a bit more
> verbose through 'foolist->base.next' instead of 'foolist->next'.
>
> Note that for lists of objects, the 'value' payload is still
> hidden behind a boxed pointer. Someday, it would be nice to do:
>
> struct FooList {
> FooList *next;
> Foo value;
> };
>
> for one less level of malloc for each list element. This patch
> is a step in that direction (now that 'next' is no longer at a
> fixed non-zero offset within the struct, we can store more than
> just a pointer's-worth of data as the value payload), but the
> actual conversion would be a task for another series, as it will
> touch a lot of code.
>
> Signed-off-by: Eric Blake <address@hidden>
Bonus: qapi-types.h shrinks by 5%.
qapi-types.h | 350 +++++++++++------------------------------------------------
qapi-visit.c | 140 +++++++++++------------
2 files changed, 140 insertions(+), 350 deletions(-)
- Re: [Qemu-devel] [PATCH v11 03/15] qapi: Forbid 'any' inside an alternate, (continued)
[Qemu-devel] [PATCH v11 06/15] qapi: Visit variants in visit_type_FOO_fields(), Eric Blake, 2016/02/18
[Qemu-devel] [PATCH v11 10/15] qapi: Emit structs used as variants in topological order, Eric Blake, 2016/02/18
[Qemu-devel] [PATCH v11 09/15] qapi: Adjust layout of FooList types, Eric Blake, 2016/02/18
- Re: [Qemu-devel] [PATCH v11 09/15] qapi: Adjust layout of FooList types,
Markus Armbruster <=
[Qemu-devel] [PATCH v11 14/15] qapi: Delete visit_start_union(), gen_visit_implicit_struct(), Eric Blake, 2016/02/18
[Qemu-devel] [PATCH v11 08/15] qapi-visit: Less indirection in visit_type_Foo_fields(), Eric Blake, 2016/02/18
[Qemu-devel] [PATCH v11 11/15] qapi-visit: Use common idiom in gen_visit_fields_decl(), Eric Blake, 2016/02/18
[Qemu-devel] [PATCH v11 12/15] qapi: Don't box struct branch of alternate, Eric Blake, 2016/02/18