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