>
> - What are the memory layout optimizations described here? From a first
> glance this looks purely syntactic.
The compiler could “refactor” the payloads among all enum cases to maximise
overlapping. If you know that an enum’s payload always contains a
reference-counted or shared object, or that a element is always at a given
position in the payload, you can operate on the payload’s elements without
needing to switch.
(crude example)
enum EditorMode {
case .textEditor(UIViewController)
case .imageEditor(UIViewController)
// This would reduce to just returning the payload without switching.
// We could even think about generating a “EditorMode.0 : UIViewController”
accessor
var editorController: UIViewController {
switch self {
case .textEditor(let t): return t
case .imageEditor(let i): return i
}
}
}
- Karl
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution