Commit 643b9ec0 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: tidy up switch case expansion

No functional changes.

Change-Id: I0961227e8a7be2d7c611452896843b6955303fa6
Reviewed-on: https://go-review.googlesource.com/26768Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
parent a9266eef
......@@ -352,22 +352,22 @@ func casebody(sw *Node, typeswvar *Node) {
needvar := n.List.Len() != 1 || n.List.First().Op == OLITERAL
jmp := Nod(OGOTO, autolabel(".s"), nil)
if n.List.Len() == 0 {
switch n.List.Len() {
case 0:
// default
if def != nil {
Yyerror("more than one default case")
}
// reuse original default case
n.Right = jmp
def = n
}
if n.List.Len() == 1 {
case 1:
// one case -- reuse OCASE node
n.Left = n.List.First()
n.Right = jmp
n.List.Set(nil)
cas = append(cas, n)
} else {
default:
// expand multi-valued cases
for _, n1 := range n.List.Slice() {
cas = append(cas, Nod(OCASE, n1, jmp))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment