# InternPool: ability to encode enums · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/50bebb9e21c7e131522bec467b477ed7f55feb91)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 50bebb9e21c7e131522bec467b477ed7f55feb91

Requested commit: 50bebb9e21c7e131522bec467b477ed7f55feb91

Commit: 50bebb9e21c7e131522bec467b477ed7f55feb91

Tree: 91fc8d696f772b909218c6544bc03d9c9f41b448

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
InternPool: ability to encode enums

This introduces a string table into InternPool as well as a curious new
field called `maps` which is an array list of array hash maps with
void/void key/value.

Some types such as enums, structs, and unions need to store mappings
from field names to field index, or value to field index. In such cases,
they will store the underlying field names and values directly, relying
on one of these maps, stored separately, to provide lookup.

This allows the InternPool to be serialized via simple array copies,
omitting all the maps, which are only used for optimizing lookup based
on field name or field value.

When the InternPool is deserialized it can be loaded via simple array
copies, and then as a post-processing step the field name maps can be
generated as extra metadata that is tacked on.

This commit provides two encodings for enums - one when the integer tag
type is explicitly provided and one when it is not. This is simpler than
the previous setup, which has three encodings.

Previous sizes:
 * EnumSimple: 40 bytes + 16 bytes per field
 * EnumNumbered: 80 bytes + 24 bytes per field
 * EnumFull: 184 bytes + 24 bytes per field

Sizes after this commit:
 * type_enum_explicit: 24 bytes + 8 bytes per field
 * type_enum_auto: 16 bytes + 4 bytes per field

```

## Parents

- [1c7095cb7dfcba3537edf3624a61046c9b772b1f](https://git.cafe/gitcafe/zig/commit/1c7095cb7dfcba3537edf3624a61046c9b772b1f?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/50bebb9e21c7e131522bec467b477ed7f55feb91?format=markdown)
