[swift-evolution] [Review] SE-0155: Normalize Enum Case Representation
Karl Wagner
razielim at gmail.com
Sat Feb 18 11:06:31 CST 2017
>
> - 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170218/5bcdd22b/attachment.html>
More information about the swift-evolution
mailing list