Commit bd83cc6d authored by Marvin Stenger's avatar Marvin Stenger Committed by Brad Fitzpatrick

cmd/compile: prettify loop iterations

This commit replaces some of

for i := len(x) - 1; i >= 0; i-- {...}

style loops, which do not rely on reverse iteration order.

Change-Id: I5542834286562da058200c06e7a173b13760e54d
Reviewed-on: https://go-review.googlesource.com/21044Reviewed-by: default avatarKeith Randall <khr@golang.org>
parent ca5417b8
...@@ -455,15 +455,15 @@ func escAnalyze(all []*Node, recursive bool) { ...@@ -455,15 +455,15 @@ func escAnalyze(all []*Node, recursive bool) {
e.nodeEscState(&e.theSink).Escloopdepth = -1 e.nodeEscState(&e.theSink).Escloopdepth = -1
e.recursive = recursive e.recursive = recursive
for i := len(all) - 1; i >= 0; i-- { for _, n := range all {
if n := all[i]; n.Op == ODCLFUNC { if n.Op == ODCLFUNC {
n.Esc = EscFuncPlanned n.Esc = EscFuncPlanned
} }
} }
// flow-analyze functions // flow-analyze functions
for i := len(all) - 1; i >= 0; i-- { for _, n := range all {
if n := all[i]; n.Op == ODCLFUNC { if n.Op == ODCLFUNC {
escfunc(e, n) escfunc(e, n)
} }
} }
...@@ -477,8 +477,8 @@ func escAnalyze(all []*Node, recursive bool) { ...@@ -477,8 +477,8 @@ func escAnalyze(all []*Node, recursive bool) {
} }
// for all top level functions, tag the typenodes corresponding to the param nodes // for all top level functions, tag the typenodes corresponding to the param nodes
for i := len(all) - 1; i >= 0; i-- { for _, n := range all {
if n := all[i]; n.Op == ODCLFUNC { if n.Op == ODCLFUNC {
esctag(e, n) esctag(e, n)
} }
} }
......
...@@ -436,9 +436,7 @@ func Main() { ...@@ -436,9 +436,7 @@ func Main() {
if Debug['l'] != 0 { if Debug['l'] != 0 {
// Find functions that can be inlined and clone them before walk expands them. // Find functions that can be inlined and clone them before walk expands them.
visitBottomUp(xtop, func(list []*Node, recursive bool) { visitBottomUp(xtop, func(list []*Node, recursive bool) {
// TODO: use a range statement here if the order does not matter for _, n := range list {
for i := len(list) - 1; i >= 0; i-- {
n := list[i]
if n.Op == ODCLFUNC { if n.Op == ODCLFUNC {
caninl(n) caninl(n)
inlcalls(n) inlcalls(n)
......
...@@ -2801,9 +2801,8 @@ func keydup(n *Node, hash map[uint32][]*Node) { ...@@ -2801,9 +2801,8 @@ func keydup(n *Node, hash map[uint32][]*Node) {
case CTSTR: case CTSTR:
h = 0 h = 0
s := n.Val().U.(string) s := n.Val().U.(string)
for i := len(n.Val().U.(string)); i > 0; i-- { for i := 0; i < len(s); i++ {
h = h*PRIME1 + uint32(s[0]) h = h*PRIME1 + uint32(s[i])
s = s[1:]
} }
} }
......
...@@ -163,11 +163,10 @@ func postDominators(f *Func) []*Block { ...@@ -163,11 +163,10 @@ func postDominators(f *Func) []*Block {
// find the exit blocks // find the exit blocks
var exits []*Block var exits []*Block
for i := len(f.Blocks) - 1; i >= 0; i-- { for _, b := range f.Blocks {
switch f.Blocks[i].Kind { switch b.Kind {
case BlockExit, BlockRet, BlockRetJmp, BlockCall, BlockCheck: case BlockExit, BlockRet, BlockRetJmp, BlockCall, BlockCheck:
exits = append(exits, f.Blocks[i]) exits = append(exits, b)
break
} }
} }
......
...@@ -155,7 +155,7 @@ func (s *stackAllocState) stackalloc() { ...@@ -155,7 +155,7 @@ func (s *stackAllocState) stackalloc() {
slots = make([]int, n) slots = make([]int, n)
s.slots = slots s.slots = slots
} }
for i := f.NumValues() - 1; i >= 0; i-- { for i := range slots {
slots[i] = -1 slots[i] = -1
} }
......
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