runtime: properly turn pointer into empty interface when hashing
Этот коммит содержится в:
родитель
cfe971d723
коммит
7b44fcd865
3 изменённых файлов: 36 добавлений и 1 удалений
|
@ -563,7 +563,7 @@ func hashmapInterfaceHash(itf interface{}, seed uintptr) uint32 {
|
|||
}
|
||||
|
||||
func hashmapInterfacePtrHash(iptr unsafe.Pointer, size uintptr, seed uintptr) uint32 {
|
||||
_i := *(*_interface)(iptr)
|
||||
_i := *(*interface{})(iptr)
|
||||
return hashmapInterfaceHash(_i, seed)
|
||||
}
|
||||
|
||||
|
|
34
testdata/map.go
предоставленный
34
testdata/map.go
предоставленный
|
@ -129,6 +129,8 @@ func main() {
|
|||
floatcmplx()
|
||||
|
||||
mapgrow()
|
||||
|
||||
interfacerehash()
|
||||
}
|
||||
|
||||
func floatcmplx() {
|
||||
|
@ -274,3 +276,35 @@ func mapgrow() {
|
|||
}
|
||||
println("done")
|
||||
}
|
||||
|
||||
type Counter interface {
|
||||
count() int
|
||||
}
|
||||
|
||||
type counter struct {
|
||||
i int
|
||||
}
|
||||
|
||||
func (c *counter) count() int {
|
||||
return c.i
|
||||
}
|
||||
|
||||
func interfacerehash() {
|
||||
m := make(map[Counter]int)
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
c := &counter{i}
|
||||
m[c] = i
|
||||
}
|
||||
|
||||
var failures int
|
||||
for k, v := range m {
|
||||
if got := m[k]; got != v {
|
||||
println("lookup failure got", got, "want", v)
|
||||
failures++
|
||||
}
|
||||
}
|
||||
if failures == 0 {
|
||||
println("no interface lookup failures")
|
||||
}
|
||||
}
|
||||
|
|
1
testdata/map.txt
предоставленный
1
testdata/map.txt
предоставленный
|
@ -80,3 +80,4 @@ tested growing of a map
|
|||
2
|
||||
2
|
||||
done
|
||||
no interface lookup failures
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче