1
0
mirror of https://github.com/golang/go synced 2024-11-12 04:30:22 -07:00

cmd/compile/internal/gc: type.go cleanup

Follow up to CL 20494 addressing Type.Copy and a few other tiny
cleanups.

Change-Id: I3d0913a9f50a22ac2fd802858b1a94c15c5cb1bc
Reviewed-on: https://go-review.googlesource.com/20501
Run-TryBot: Dave Cheney <dave@cheney.net>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Dave Cheney 2016-03-10 13:54:02 +11:00
parent 2339b131d6
commit 9d77ad8d34

View File

@ -180,13 +180,12 @@ func (t *Type) Copy() *Type {
if t == nil {
return nil
}
nt := new(Type)
*nt = *t
nt := *t
// TODO(mdempsky): Find out why this is necessary and explain.
if t.Orig == t {
nt.Orig = nt
nt.Orig = &nt
}
return nt
return &nt
}
// Iter provides an abstraction for iterating across struct fields and
@ -267,10 +266,7 @@ func (t *Type) SimpleString() string {
func (t *Type) Equal(u ssa.Type) bool {
x, ok := u.(*Type)
if !ok {
return false
}
return Eqtype(t, x)
return ok && Eqtype(t, x)
}
// Compare compares types for purposes of the SSA back
@ -368,20 +364,16 @@ func (t *Type) cmp(x *Type) ssa.Cmp {
}
}
csym := t.Sym.cmpsym(x.Sym)
if csym != ssa.CMPeq {
return csym
if c := t.Sym.cmpsym(x.Sym); c != ssa.CMPeq {
return c
}
if x.Sym != nil {
// Syms non-nil, if vargens match then equal.
if t.Vargen == x.Vargen {
return ssa.CMPeq
if t.Vargen != x.Vargen {
return cmpForNe(t.Vargen < x.Vargen)
}
if t.Vargen < x.Vargen {
return ssa.CMPlt
}
return ssa.CMPgt
return ssa.CMPeq
}
// both syms nil, look at structure below.
@ -481,8 +473,7 @@ func (t *Type) cmp(x *Type) ssa.Cmp {
panic(e)
}
c := t.Down.cmp(x.Down)
if c != ssa.CMPeq {
if c := t.Down.cmp(x.Down); c != ssa.CMPeq {
return c
}
return t.Type.cmp(x.Type)