1
0
mirror of https://github.com/golang/go synced 2024-11-19 18:44:41 -07:00

cmd/compile: turn some pointer params into results

These are likely from the time when gc was written in C. There is no
need for any of these to be passed pointers, as the previous values are
not kept in any way, and the pointers are never nil. Others were left
untouched as they fell into one of these useful cases.

While at it, also turn some 0/1 integers into booleans.

Passes toolstash -cmp on std cmd.

Change-Id: Id3a9c9e84ef89536c4dc69a7fdbacd0fd7a76a9b
Reviewed-on: https://go-review.googlesource.com/72990
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Daniel Martí 2017-10-24 17:15:30 +01:00
parent f3884680fc
commit d5960e3043
4 changed files with 28 additions and 35 deletions

View File

@ -13,7 +13,7 @@ import (
// range
func typecheckrange(n *Node) {
var toomany int
var toomany bool
var why string
var t1 *types.Type
var t2 *types.Type
@ -50,7 +50,7 @@ func typecheckrange(n *Node) {
}
n.Type = t
toomany = 0
toomany = false
switch t.Etype {
default:
yyerrorl(n.Pos, "cannot range over %L", n.Right)
@ -73,7 +73,7 @@ func typecheckrange(n *Node) {
t1 = t.Elem()
t2 = nil
if n.List.Len() == 2 {
toomany = 1
toomany = true
}
case TSTRING:
@ -81,7 +81,7 @@ func typecheckrange(n *Node) {
t2 = types.Runetype
}
if n.List.Len() > 2 || toomany != 0 {
if n.List.Len() > 2 || toomany {
yyerrorl(n.Pos, "too many variables in range")
}

View File

@ -1800,35 +1800,32 @@ func hashmem(t *types.Type) *Node {
return n
}
func ifacelookdot(s *types.Sym, t *types.Type, followptr *bool, ignorecase bool) *types.Field {
*followptr = false
func ifacelookdot(s *types.Sym, t *types.Type, ignorecase bool) (m *types.Field, followptr bool) {
if t == nil {
return nil
return nil, false
}
var m *types.Field
path, ambig := dotpath(s, t, &m, ignorecase)
if path == nil {
if ambig {
yyerror("%v.%v is ambiguous", t, s)
}
return nil
return nil, false
}
for _, d := range path {
if d.field.Type.IsPtr() {
*followptr = true
followptr = true
break
}
}
if m.Type.Etype != TFUNC || m.Type.Recv() == nil {
yyerror("%v.%v is a field, not a method", t, s)
return nil
return nil, followptr
}
return m
return m, followptr
}
func implements(t, iface *types.Type, m, samename **types.Field, ptr *int) bool {
@ -1873,11 +1870,10 @@ func implements(t, iface *types.Type, m, samename **types.Field, ptr *int) bool
if im.Broke() {
continue
}
var followptr bool
tm := ifacelookdot(im.Sym, t, &followptr, false)
tm, followptr := ifacelookdot(im.Sym, t, false)
if tm == nil || tm.Nointerface() || !eqtype(tm.Type, im.Type) {
if tm == nil {
tm = ifacelookdot(im.Sym, t, &followptr, true)
tm, followptr = ifacelookdot(im.Sym, t, true)
}
*m = im
*samename = tm

View File

@ -3910,17 +3910,17 @@ func (n *Node) isterminating() bool {
if n.HasBreak() {
return false
}
def := 0
def := false
for _, n1 := range n.List.Slice() {
if !n1.Nbody.isterminating() {
return false
}
if n1.List.Len() == 0 { // default
def = 1
def = true
}
}
if n.Op != OSELECT && def == 0 {
if n.Op != OSELECT && !def {
return false
}
return true

View File

@ -2481,9 +2481,8 @@ func aliased(n *Node, all []*Node, i int) bool {
// Also record whether there are any writes to main memory.
// Also record whether there are any writes to variables
// whose addresses have been taken.
memwrite := 0
varwrite := 0
memwrite := false
varwrite := false
for _, an := range all[:i] {
a := outervalue(an.Left)
@ -2492,18 +2491,18 @@ func aliased(n *Node, all []*Node, i int) bool {
}
if a.Op != ONAME {
memwrite = 1
memwrite = true
continue
}
switch n.Class() {
default:
varwrite = 1
varwrite = true
continue
case PAUTO, PPARAM, PPARAMOUT:
if n.Addrtaken() {
varwrite = 1
varwrite = true
continue
}
@ -2519,7 +2518,7 @@ func aliased(n *Node, all []*Node, i int) bool {
// that are being written.
// If no computed addresses are affected by the writes, no aliasing.
if memwrite == 0 && varwrite == 0 {
if !memwrite && !varwrite {
return false
}
@ -3208,7 +3207,7 @@ func copyany(n *Node, init *Nodes, runtimecall bool) *Node {
return nlen
}
func eqfor(t *types.Type, needsize *int) *Node {
func eqfor(t *types.Type) (n *Node, needsize bool) {
// Should only arrive here with large memory or
// a struct/array containing a non-memory field/element.
// Small memory is handled inline, and single non-memory
@ -3217,8 +3216,7 @@ func eqfor(t *types.Type, needsize *int) *Node {
case AMEM:
n := syslook("memequal")
n = substArgTypes(n, t, t)
*needsize = 1
return n
return n, true
case ASPECIAL:
sym := typesymprefix(".eq", t)
n := newname(sym)
@ -3229,11 +3227,10 @@ func eqfor(t *types.Type, needsize *int) *Node {
ntype.Rlist.Append(anonfield(types.Types[TBOOL]))
ntype = typecheck(ntype, Etype)
n.Type = ntype.Type
*needsize = 0
return n
return n, false
}
Fatalf("eqfor %v", t)
return nil
return nil, false
}
// The result of walkcompare MUST be assigned back to n, e.g.
@ -3353,11 +3350,11 @@ func walkcompare(n *Node, init *Nodes) *Node {
ar = typecheck(ar, Etop)
init.Append(ar)
var needsize int
call := nod(OCALL, eqfor(t, &needsize), nil)
fn, needsize := eqfor(t)
call := nod(OCALL, fn, nil)
call.List.Append(pl)
call.List.Append(pr)
if needsize != 0 {
if needsize {
call.List.Append(nodintconst(t.Width))
}
res := call