mirror of https://github.com/golang/go.git
cmd/compile: remove a few unnecessary gotos
Rework the logic to remove them. These were the low hanging fruit, with labels that were used only once and logic that was fairly straightforward. Change-Id: I02a01c59c247b8b2972d8d73ff23f96f271de038 Reviewed-on: https://go-review.googlesource.com/63410 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
f260ae6523
commit
83f0af1742
|
|
@ -1165,19 +1165,17 @@ func dtypesym(t *types.Type) *types.Sym {
|
|||
dupok = obj.DUPOK
|
||||
}
|
||||
|
||||
if myimportpath == "runtime" && (tbase == types.Types[tbase.Etype] || tbase == types.Bytetype || tbase == types.Runetype || tbase == types.Errortype) { // int, float, etc
|
||||
goto ok
|
||||
if myimportpath != "runtime" || (tbase != types.Types[tbase.Etype] && tbase != types.Bytetype && tbase != types.Runetype && tbase != types.Errortype) { // int, float, etc
|
||||
// named types from other files are defined only by those files
|
||||
if tbase.Sym != nil && !tbase.Local() {
|
||||
return s
|
||||
}
|
||||
// TODO(mdempsky): Investigate whether this can happen.
|
||||
if isforw[tbase.Etype] {
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
// named types from other files are defined only by those files
|
||||
if tbase.Sym != nil && !tbase.Local() {
|
||||
return s
|
||||
}
|
||||
if isforw[tbase.Etype] {
|
||||
return s
|
||||
}
|
||||
|
||||
ok:
|
||||
ot := 0
|
||||
lsym := s.Linksym()
|
||||
switch t.Etype {
|
||||
|
|
|
|||
|
|
@ -1847,11 +1847,12 @@ func implements(t, iface *types.Type, m, samename **types.Field, ptr *int) bool
|
|||
// and then do one loop.
|
||||
|
||||
if t.IsInterface() {
|
||||
Outer:
|
||||
for _, im := range iface.Fields().Slice() {
|
||||
for _, tm := range t.Fields().Slice() {
|
||||
if tm.Sym == im.Sym {
|
||||
if eqtype(tm.Type, im.Type) {
|
||||
goto found
|
||||
continue Outer
|
||||
}
|
||||
*m = im
|
||||
*samename = tm
|
||||
|
|
@ -1864,7 +1865,6 @@ func implements(t, iface *types.Type, m, samename **types.Field, ptr *int) bool
|
|||
*samename = nil
|
||||
*ptr = 0
|
||||
return false
|
||||
found:
|
||||
}
|
||||
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -621,6 +621,7 @@ func typecheck1(n *Node, top int) *Node {
|
|||
// the only conversion that isn't a no-op is concrete == interface.
|
||||
// in that case, check comparability of the concrete type.
|
||||
// The conversion allocates, so only do it if the concrete type is huge.
|
||||
converted := false
|
||||
if r.Type.Etype != TBLANK {
|
||||
aop = assignop(l.Type, r.Type, nil)
|
||||
if aop != 0 {
|
||||
|
|
@ -639,11 +640,11 @@ func typecheck1(n *Node, top int) *Node {
|
|||
}
|
||||
|
||||
t = r.Type
|
||||
goto converted
|
||||
converted = true
|
||||
}
|
||||
}
|
||||
|
||||
if l.Type.Etype != TBLANK {
|
||||
if !converted && l.Type.Etype != TBLANK {
|
||||
aop = assignop(r.Type, l.Type, nil)
|
||||
if aop != 0 {
|
||||
if l.Type.IsInterface() && !r.Type.IsInterface() && !IsComparable(r.Type) {
|
||||
|
|
@ -664,7 +665,6 @@ func typecheck1(n *Node, top int) *Node {
|
|||
}
|
||||
}
|
||||
|
||||
converted:
|
||||
et = t.Etype
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1999,8 +1999,6 @@ func mkdotargslice(typ *types.Type, args []*Node, init *Nodes, ddd *Node) *Node
|
|||
// return expr-list
|
||||
// func(expr-list)
|
||||
func ascompatte(call *Node, isddd bool, lhs *types.Type, rhs []*Node, fp int, init *Nodes) []*Node {
|
||||
var nn []*Node
|
||||
|
||||
// f(g()) where g has multiple return values
|
||||
if len(rhs) == 1 && rhs[0].Type.IsFuncArgStruct() {
|
||||
// optimization - can do block copy
|
||||
|
|
@ -2008,8 +2006,9 @@ func ascompatte(call *Node, isddd bool, lhs *types.Type, rhs []*Node, fp int, in
|
|||
nl := nodarg(lhs, fp)
|
||||
nr := nod(OCONVNOP, rhs[0], nil)
|
||||
nr.Type = nl.Type
|
||||
nn = []*Node{convas(nod(OAS, nl, nr), init)}
|
||||
goto ret
|
||||
n := convas(nod(OAS, nl, nr), init)
|
||||
n.SetTypecheck(1)
|
||||
return []*Node{n}
|
||||
}
|
||||
|
||||
// conversions involved.
|
||||
|
|
@ -2033,6 +2032,7 @@ func ascompatte(call *Node, isddd bool, lhs *types.Type, rhs []*Node, fp int, in
|
|||
// If there's a ... parameter (which is only valid as the final
|
||||
// parameter) and this is not a ... call expression,
|
||||
// then assign the remaining arguments as a slice.
|
||||
var nn []*Node
|
||||
for i, nl := range lhs.FieldSlice() {
|
||||
var nr *Node
|
||||
if nl.Isddd() && !isddd {
|
||||
|
|
@ -2043,13 +2043,10 @@ func ascompatte(call *Node, isddd bool, lhs *types.Type, rhs []*Node, fp int, in
|
|||
|
||||
a := nod(OAS, nodarg(nl, fp), nr)
|
||||
a = convas(a, init)
|
||||
a.SetTypecheck(1)
|
||||
nn = append(nn, a)
|
||||
}
|
||||
|
||||
ret:
|
||||
for _, n := range nn {
|
||||
n.SetTypecheck(1)
|
||||
}
|
||||
return nn
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue