mirror of
https://github.com/golang/go
synced 2024-11-19 22:04:44 -07:00
cmd/compile: deduplicate a few lines in swt.go
Noticed while reading some code that the two branches in this loop body shared the last statements. Rewrite it in a way that they are not duplicated. Passes toolstash -cmp on std. Change-Id: I3356ca9fa37c32eee496e221d7830bfc581dade1 Reviewed-on: https://go-review.googlesource.com/66470 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
4f70a2a699
commit
1fbeccb15a
@ -273,21 +273,15 @@ func (s *exprSwitch) walk(sw *Node) {
|
||||
|
||||
// handle the cases in order
|
||||
for len(cc) > 0 {
|
||||
// deal with expressions one at a time
|
||||
if !okforcmp[t.Etype] || !cc[0].isconst {
|
||||
a := s.walkCases(cc[:1])
|
||||
cas = append(cas, a)
|
||||
cc = cc[1:]
|
||||
continue
|
||||
run := 1
|
||||
if okforcmp[t.Etype] && cc[0].isconst {
|
||||
// do binary search on runs of constants
|
||||
for ; run < len(cc) && cc[run].isconst; run++ {
|
||||
}
|
||||
// sort and compile constants
|
||||
sort.Sort(caseClauseByConstVal(cc[:run]))
|
||||
}
|
||||
|
||||
// do binary search on runs of constants
|
||||
var run int
|
||||
for run = 1; run < len(cc) && cc[run].isconst; run++ {
|
||||
}
|
||||
|
||||
// sort and compile constants
|
||||
sort.Sort(caseClauseByConstVal(cc[:run]))
|
||||
a := s.walkCases(cc[:run])
|
||||
cas = append(cas, a)
|
||||
cc = cc[run:]
|
||||
|
Loading…
Reference in New Issue
Block a user