]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/gc: type.go cleanup
authorDave Cheney <dave@cheney.net>
Thu, 10 Mar 2016 02:54:02 +0000 (13:54 +1100)
committerDave Cheney <dave@cheney.net>
Thu, 10 Mar 2016 03:53:53 +0000 (03:53 +0000)
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>
src/cmd/compile/internal/gc/type.go

index 29cc73ad1fe85717bced2316dcd7e7d02340ad7d..7b4beb06cc019d5d7bd9c5d96caebfc84fd0f080 100644 (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)