Commit 33fd4535 authored by Ingo Oeser's avatar Ingo Oeser Committed by Ian Lance Taylor

cmd/compile: use range construct

so the code is more readable.

Also use n[i] = val instead of n = append(n, val),
because this avoids a function call to append.

NOTE: compiles, but I had trouble running toolstash -cmp and need sleep
now.

@Ian this might save you some grunt work :-)

Change-Id: I2a4c70396c58905f7d5aabf83f3020f11dea0e89
Reviewed-on: https://go-review.googlesource.com/20430Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent c52cb1fe
...@@ -347,9 +347,9 @@ func (p *importer) fieldList() []*Node { ...@@ -347,9 +347,9 @@ func (p *importer) fieldList() []*Node {
if i == 0 { if i == 0 {
return nil return nil
} }
n := make([]*Node, 0, i) n := make([]*Node, i)
for ; i > 0; i-- { for i := range n {
n = append(n, p.field()) n[i] = p.field()
} }
return n return n
} }
...@@ -394,9 +394,9 @@ func (p *importer) methodList() []*Node { ...@@ -394,9 +394,9 @@ func (p *importer) methodList() []*Node {
if i == 0 { if i == 0 {
return nil return nil
} }
n := make([]*Node, 0, i) n := make([]*Node, i)
for ; i > 0; i-- { for i := range n {
n = append(n, p.method()) n[i] = p.method()
} }
return n return n
} }
...@@ -440,9 +440,9 @@ func (p *importer) paramList() []*Node { ...@@ -440,9 +440,9 @@ func (p *importer) paramList() []*Node {
named = false named = false
} }
// i > 0 // i > 0
n := make([]*Node, 0, i) n := make([]*Node, i)
for ; i > 0; i-- { for i := range n {
n = append(n, p.param(named)) n[i] = p.param(named)
} }
return n return n
} }
...@@ -551,9 +551,9 @@ func (p *importer) float(x *Mpflt) { ...@@ -551,9 +551,9 @@ func (p *importer) float(x *Mpflt) {
// parser.go:stmt_list // parser.go:stmt_list
func (p *importer) nodeList() []*Node { func (p *importer) nodeList() []*Node {
c := p.int() c := p.int()
s := make([]*Node, 0, c) s := make([]*Node, c)
for i := 0; i < c; i++ { for i := range s {
s = append(s, p.node()) s[i] = p.node()
} }
return s return s
} }
...@@ -817,7 +817,7 @@ func (p *importer) string() string { ...@@ -817,7 +817,7 @@ func (p *importer) string() string {
} else { } else {
p.buf = p.buf[:n] p.buf = p.buf[:n]
} }
for i := 0; i < n; i++ { for i := range p.buf {
p.buf[i] = p.byte() p.buf[i] = p.byte()
} }
return string(p.buf) return string(p.buf)
......
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