[swift-dev] inefficient enum layout with optionals
Kelvin Ma
kelvin13ma at gmail.com
Mon Nov 6 02:46:37 CST 2017
i noticed that this enum takes up 9 bytes of storage
1> enum QuantizationTable
2. {
3. case q8 (UnsafeMutablePointer<UInt8>),
4. q16(UnsafeMutablePointer<UInt16>)
5. }
6> MemoryLayout<QuantizationTable>.size
$R0: Int = 9
but when i make it optional, it takes up 10
7> MemoryLayout<QuantizationTable?>.size
$R1: Int = 10
can’t the compiler just tack the nil case onto the original enum as a third
case? after all, this works fine
1> enum QuantizationTable
2. {
3. case q8 (UnsafeMutablePointer<UInt8>),
4. q16(UnsafeMutablePointer<UInt16>),
5. none
6. }
7> MemoryLayout<QuantizationTable>.size
$R0: Int = 9
the way i’m using it atm it all gets padded to 16 anyway so i don’t care
that much but is this something that’s being looked at?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20171106/18e792e2/attachment.html>
More information about the swift-dev
mailing list