]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: simplify typehash
authorMatthew Dempsky <mdempsky@google.com>
Thu, 17 Mar 2016 08:39:59 +0000 (01:39 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Thu, 17 Mar 2016 19:38:21 +0000 (19:38 +0000)
We never need a type hash for a method type, so skip trying to
overwrite Thistuple.

Change-Id: I8de6480ba5fd321dfa134facf7661461d298840e
Reviewed-on: https://go-review.googlesource.com/20795
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/compile/internal/gc/subr.go

index 126959b2c16271b40c511a356effab78579b3fd9..26d45700e5d0a0be8b9f36e2a74b9ec470ce20c9 100644 (file)
@@ -1219,30 +1219,15 @@ func syslook(name string) *Node {
        return s.Def
 }
 
-// compute a hash value for type t.
-// if t is a method type, ignore the receiver
-// so that the hash can be used in interface checks.
-// %T already contains
-// all the necessary logic to generate a representation
-// of the type that completely describes it.
-// using smprint here avoids duplicating that code.
-// using md5 here is overkill, but i got tired of
-// accidental collisions making the runtime think
-// two types are equal when they really aren't.
+// typehash computes a hash value for type t to use in type switch
+// statements.
 func typehash(t *Type) uint32 {
-       var p string
+       // Tconv already contains all the necessary logic to generate
+       // a representation that completely describes the type, so using
+       // it here avoids duplicating that code.
+       p := Tconv(t, FmtLeft|FmtUnsigned)
 
-       if t.Thistuple != 0 {
-               // hide method receiver from Tpretty
-               t.Thistuple = 0
-
-               p = Tconv(t, FmtLeft|FmtUnsigned)
-               t.Thistuple = 1
-       } else {
-               p = Tconv(t, FmtLeft|FmtUnsigned)
-       }
-
-       //print("typehash: %s\n", p);
+       // Using MD5 is overkill, but reduces accidental collisions.
        h := md5.Sum([]byte(p))
        return binary.LittleEndian.Uint32(h[:4])
 }