aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorMarvin Stenger <marvin.stenger94@gmail.com>2016-03-23 16:35:50 +0100
committerBrad Fitzpatrick <bradfitz@golang.org>2016-03-23 22:49:49 +0000
commitbd83cc6dae36399f3c8fd99bd4ceea6570c70f5a (patch)
treea33c6d22b6afeb5e575ed6bc4f1d42ce7e07cebf /src/cmd
parentca5417b8e0c859aa5537247aed03316bfd3f5a66 (diff)
downloadgo-bd83cc6dae36399f3c8fd99bd4ceea6570c70f5a.tar.xz
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/21044 Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/compile/internal/gc/esc.go12
-rw-r--r--src/cmd/compile/internal/gc/main.go4
-rw-r--r--src/cmd/compile/internal/gc/typecheck.go5
-rw-r--r--src/cmd/compile/internal/ssa/dom.go7
-rw-r--r--src/cmd/compile/internal/ssa/stackalloc.go2
5 files changed, 13 insertions, 17 deletions
diff --git a/src/cmd/compile/internal/gc/esc.go b/src/cmd/compile/internal/gc/esc.go
index 31ba300d7f..037ddf4822 100644
--- a/src/cmd/compile/internal/gc/esc.go
+++ b/src/cmd/compile/internal/gc/esc.go
@@ -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)
}
}
diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go
index 92589a8e0e..09b433d7f2 100644
--- a/src/cmd/compile/internal/gc/main.go
+++ b/src/cmd/compile/internal/gc/main.go
@@ -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)
diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go
index 2bc216c75d..1f9b1c8b4a 100644
--- a/src/cmd/compile/internal/gc/typecheck.go
+++ b/src/cmd/compile/internal/gc/typecheck.go
@@ -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])
}
}
diff --git a/src/cmd/compile/internal/ssa/dom.go b/src/cmd/compile/internal/ssa/dom.go
index 7de8c354a1..d4dccda058 100644
--- a/src/cmd/compile/internal/ssa/dom.go
+++ b/src/cmd/compile/internal/ssa/dom.go
@@ -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)
}
}
diff --git a/src/cmd/compile/internal/ssa/stackalloc.go b/src/cmd/compile/internal/ssa/stackalloc.go
index 253c83f163..ad8b7be9ba 100644
--- a/src/cmd/compile/internal/ssa/stackalloc.go
+++ b/src/cmd/compile/internal/ssa/stackalloc.go
@@ -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
}