<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class=""><br class=""></div><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">- What are the memory layout optimizations described here? From a first glance this looks purely syntactic.</div></div></div></div></blockquote></div><br class=""><div class=""><span id="x-apple-selection:end"></span>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.</div><div class=""><br class=""></div><div class="">(crude example)</div><div class=""><br class=""></div><div class=""><font face="Courier" class="">enum EditorMode {</font></div><div class=""><font face="Courier" class=""> case .textEditor(UIViewController)</font></div><div class=""><font face="Courier" class=""> case .imageEditor(UIViewController)</font></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><br class=""></div><div class=""><font face="Courier" class="">// This would reduce to just returning the payload without switching.</font></div><div class=""><font face="Courier" class="">// We could even think about generating a “EditorMode.0 : UIViewController” accessor</font></div><div class=""><font face="Courier" class=""><br class=""></font></div></blockquote><div class=""><font face="Courier" class=""> var editorController: UIViewController {</font></div><div class=""><font face="Courier" class=""> switch self { </font></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class=""><font face="Courier" class=""> case .textEditor(let t): return t</font></div><div class=""><font face="Courier" class=""> case .imageEditor(let i): return i</font></div><div class=""><font face="Courier" class="">}</font></div></blockquote><div class=""><font face="Courier" class=""> }</font></div><div class=""><font face="Courier" class="">}</font></div><div class=""><br class=""></div><div class="">- Karl</div><div class=""><br class=""></div></body></html>