Replace `WhichOneof("x")` with `which_x`. (#197)
This change refactors `OneOfField` so that all fields in a given `oneof`
construct share the same backing attributes on their container class --
`which_{oneof name}`, which holds the (string) name of the
currently-active member of the oneof named `{oneof name}` (or `None` if
no member is active), and `_value_{oneof name}`, which holds the value
of the currently-active member (or `None`).
This avoids looping through field specs in order to do an update or to
figure out which member of a `oneof` is currently active.
Since the `WhichOneof()` method is now a trivial read of a
similarly-named attribute, it can be inlined for a small decrease in
overall code size and without sacrificing readability.
As a result of these changes, the compiler now runs 4.5% faster on my
large test `.emb`.
diff --git a/compiler/front_end/attribute_checker.py b/compiler/front_end/attribute_checker.py
index 232eee8..9920db4 100644
--- a/compiler/front_end/attribute_checker.py
+++ b/compiler/front_end/attribute_checker.py
@@ -441,7 +441,7 @@
field_expression_type = type_check.unbounded_expression_type_for_physical_type(
field_type
)
- if field_expression_type.WhichOneof("type") not in (
+ if field_expression_type.which_type not in (
"integer",
"enumeration",
"boolean",