From: Daniel Martí Date: Wed, 27 Sep 2017 10:30:10 +0000 (+0100) Subject: cmd/compile: deduplicate a few lines in swt.go X-Git-Tag: go1.10beta1~755 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=1fbeccb15a56957919e087639e255b4df64062f1;p=gostls13.git 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í TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- diff --git a/src/cmd/compile/internal/gc/swt.go b/src/cmd/compile/internal/gc/swt.go index 1f401f5356..8d425506d3 100644 --- a/src/cmd/compile/internal/gc/swt.go +++ b/src/cmd/compile/internal/gc/swt.go @@ -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:]