aboutsummaryrefslogtreecommitdiff
path: root/libgo/go/reflect
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2017-01-10 03:59:20 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2017-01-10 03:59:20 +0000
commit0c22e4415fe9e88acaa99e72d33f4500d557ce68 (patch)
treeab834b9b0b4730baa18d49e3c47ae5033b722809 /libgo/go/reflect
parent8462d909a7439fb0bf7095144dbf36524c7e61ea (diff)
downloadgcc-0c22e4415fe9e88acaa99e72d33f4500d557ce68.zip
gcc-0c22e4415fe9e88acaa99e72d33f4500d557ce68.tar.gz
gcc-0c22e4415fe9e88acaa99e72d33f4500d557ce68.tar.bz2
compiler, runtime: drop size arguments to hash/equal functions
Drop the size arguments for the hash/equal functions stored in type descriptors. Types know what size they are. To make this work, generate hash/equal functions for types that can use an identity comparison but are not a standard size and alignment. Drop the multiplications by 33 in the generated hash code and the reflect package hash code. They are not necessary since we started passing a seed value around, as the seed includes the hash of the earlier values. Copy the algorithms for standard types from the Go 1.7 runtime, replacing the C functions. Reviewed-on: https://go-review.googlesource.com/34983 From-SVN: r244256
Diffstat (limited to 'libgo/go/reflect')
-rw-r--r--libgo/go/reflect/type.go26
1 files changed, 11 insertions, 15 deletions
diff --git a/libgo/go/reflect/type.go b/libgo/go/reflect/type.go
index 13b326f..4f13f14 100644
--- a/libgo/go/reflect/type.go
+++ b/libgo/go/reflect/type.go
@@ -254,8 +254,8 @@ type rtype struct {
size uintptr
hash uint32 // hash of type; avoids computation in hash tables
- hashfn func(unsafe.Pointer, uintptr, uintptr) uintptr // hash function
- equalfn func(unsafe.Pointer, unsafe.Pointer, uintptr) bool // equality function
+ hashfn func(unsafe.Pointer, uintptr) uintptr // hash function
+ equalfn func(unsafe.Pointer, unsafe.Pointer) bool // equality function
gc unsafe.Pointer // garbage collection data
string *string // string form; unnecessary but undeniably useful
@@ -2203,23 +2203,20 @@ func StructOf(fields []StructField) Type {
typ.gc = unsafe.Pointer(&gc[0])
}
- typ.hashfn = func(p unsafe.Pointer, seed, size uintptr) uintptr {
+ typ.hashfn = func(p unsafe.Pointer, seed uintptr) uintptr {
ret := seed
- for i, ft := range typ.fields {
- if i > 0 {
- ret *= 33
- }
+ for _, ft := range typ.fields {
o := unsafe.Pointer(uintptr(p) + ft.offset)
- ret = ft.typ.hashfn(o, ret, ft.typ.size)
+ ret = ft.typ.hashfn(o, ret)
}
return ret
}
- typ.equalfn = func(p, q unsafe.Pointer, size uintptr) bool {
+ typ.equalfn = func(p, q unsafe.Pointer) bool {
for _, ft := range typ.fields {
pi := unsafe.Pointer(uintptr(p) + ft.offset)
qi := unsafe.Pointer(uintptr(q) + ft.offset)
- if !ft.typ.equalfn(pi, qi, ft.typ.size) {
+ if !ft.typ.equalfn(pi, qi) {
return false
}
}
@@ -2348,19 +2345,18 @@ func ArrayOf(count int, elem Type) Type {
array.kind &^= kindDirectIface
- array.hashfn = func(p unsafe.Pointer, seed, size uintptr) uintptr {
+ array.hashfn = func(p unsafe.Pointer, seed uintptr) uintptr {
ret := seed
for i := 0; i < count; i++ {
- ret *= 33
- ret = typ.hashfn(p, ret, typ.size)
+ ret = typ.hashfn(p, ret)
p = unsafe.Pointer(uintptr(p) + typ.size)
}
return ret
}
- array.equalfn = func(p1, p2 unsafe.Pointer, size uintptr) bool {
+ array.equalfn = func(p1, p2 unsafe.Pointer) bool {
for i := 0; i < count; i++ {
- if !typ.equalfn(p1, p2, typ.size) {
+ if !typ.equalfn(p1, p2) {
return false
}
p1 = unsafe.Pointer(uintptr(p1) + typ.size)