When combining adjacent type switch cases with the same type hash, we
failed to actually remove the combined cases, so we would generate
code for them twice.
We use MD5 for type hashes, so collisions are rare, but they do
currently appear in test/fixedbugs/bug248.dir/bug2.go, which is how I
noticed this failure.
Passes toolstash-check.
Change-Id: I66729b3366b96cb8ddc8fa6f3ebea11ef6d74012
Reviewed-on: https://go-review.googlesource.com/100461
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
}
// combine adjacent cases with the same hash
- ncase := 0
- for i := 0; i < run; i++ {
- ncase++
+ var batch []caseClause
+ for i, j := 0, 0; i < run; i = j {
hash := []*Node{cc[i].node.Right}
- for j := i + 1; j < run && cc[i].hash == cc[j].hash; j++ {
+ for j = i + 1; j < run && cc[i].hash == cc[j].hash; j++ {
hash = append(hash, cc[j].node.Right)
}
cc[i].node.Right = liststmt(hash)
+ batch = append(batch, cc[i])
}
// binary search among cases to narrow by hash
- cas = append(cas, s.walkCases(cc[:ncase]))
- cc = cc[ncase:]
+ cas = append(cas, s.walkCases(batch))
+ cc = cc[run:]
}
// handle default case