Repository navigation
Conversation
A date, a time, a duration, an enum and a point each sit in the union whole, owning no allocation and needing no destructor, but copying one went out of line to a switch over every type a value can hold. Only a string, a list, a map and the rest that own something take that path now, so the two questions asked of a type on every value, how to copy it and whether destroying it has anything to do, collapse into one: does this type own an allocation. Every type in that group is trivially copyable, so its value is exactly its bytes, and a copy takes a fixed width of the union rather than choosing a member by type. Choosing by type would make the copy a jump table over the group and large enough that the copy constructor and the move assignment stop being inlined into their callers, which is the only thing that makes asking the question first worth anything. Taking the bytes is a copy of the value only while every type in the group stays trivially copyable, which a unit test now asserts of each of them by name.
Tracking
Standard development
CI Testing Labels
Documentation checklist
|
|
Some notes for review. What the code does now. Why the copy takes bytes rather than choosing a union member by type. The whole value of asking Why The one thing a reader should check is the width: a type added to the first group without being Verified. Unit and property-based suites covering the value, its shapes, the four value Measured as instructions retired, both arms built from one tree and run interleaved on a pinned |
|
A date, a time, a duration, an enum and a point each sit in the value's union whole, owning no
allocation and needing no destructor, but copying one went out of line to a switch over every type a
value can hold. Only a string, a list, a map and the rest that own something take that path now, so
the two questions asked of a type on every value, how to copy it and whether destroying it has
anything to do, collapse into one: does this type own an allocation.
Every type in that group is trivially copyable, so its value is exactly its bytes, and a copy takes
a fixed width of the union rather than choosing a member by type. Choosing by type would make the
copy a jump table over the group, and large enough that the copy constructor and the move assignment
stop being inlined into their callers, which is the only thing that makes asking the question first
worth anything. Taking the bytes is a copy of the value only while every type in the group stays
trivially copyable, which a unit test asserts of each of them by name. No query returns a different
answer.