-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Open
Labels
A-layoutArea: Memory layout of typesArea: Memory layout of typesC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
These two types could be laid out the same. However, the second type makes it explicit that the tag is logically split across different bytes. Is this something we'd be okay with the compiler doing on its own? Inspecting the next part of the tag might require an extra load.
enum ShortSlice<T> {
Empty,
Single(T),
Multi(Box<[T]>),
}
dbg!(size_of::<ShortSlice<NonZeroUsize>>()); // 24
enum ShortSlice2<T> {
ZeroOne(Option<T>),
Multi(Box<[T]>),
}
dbg!(size_of::<ShortSlice2<NonZeroUsize>>()); // 16
Metadata
Metadata
Assignees
Labels
A-layoutArea: Memory layout of typesArea: Memory layout of typesC-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.