]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: deduplicate a few lines in swt.go
authorDaniel Martí <mvdan@mvdan.cc>
Wed, 27 Sep 2017 10:30:10 +0000 (11:30 +0100)
committerDaniel Martí <mvdan@mvdan.cc>
Wed, 11 Oct 2017 23:03:47 +0000 (23:03 +0000)
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>
src/cmd/compile/internal/gc/swt.go

index 1f401f5356e6f6542eb0ad147ac33afb98da5c5f..8d425506d3407bc278bc29962ed822d106d20fa1 100644 (file)
@@ -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
-               }
-
-               // do binary search on runs of constants
-               var run int
-               for run = 1; run < len(cc) && cc[run].isconst; run++ {
+               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]))
                }
 
-               // sort and compile constants
-               sort.Sort(caseClauseByConstVal(cc[:run]))
                a := s.walkCases(cc[:run])
                cas = append(cas, a)
                cc = cc[run:]