Skip to content

Commit a1d62aa

Browse files
cherrymuigopherbot
authored andcommitted
hash/maphash: simplify pointer size checks
Use internal/goarch.PtrSize, instead of unsafe.Sizeof(uintptr(0)). Change-Id: If501ae9853ed384c4b9485e2c3b0aeba03c17685 Reviewed-on: https://go-review.googlesource.com/c/go/+/630795 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Cherry Mui <[email protected]>
1 parent efe0a86 commit a1d62aa

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/hash/maphash/maphash_runtime.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package maphash
88

99
import (
1010
"internal/abi"
11+
"internal/goarch"
1112
"internal/goexperiment"
1213
"unsafe"
1314
)
@@ -27,7 +28,7 @@ func rthash(buf []byte, seed uint64) uint64 {
2728
// The runtime hasher only works on uintptr. For 64-bit
2829
// architectures, we use the hasher directly. Otherwise,
2930
// we use two parallel hashers on the lower and upper 32 bits.
30-
if unsafe.Sizeof(uintptr(0)) == 8 {
31+
if goarch.PtrSize == 8 {
3132
return uint64(runtime_memhash(unsafe.Pointer(&buf[0]), uintptr(seed), uintptr(len)))
3233
}
3334
lo := runtime_memhash(unsafe.Pointer(&buf[0]), uintptr(seed), uintptr(len))
@@ -54,7 +55,7 @@ func comparableHash[T comparable](v T, seed Seed) uint64 {
5455
} else {
5556
hasher = (*abi.OldMapType)(unsafe.Pointer(mTyp)).Hasher
5657
}
57-
if unsafe.Sizeof(uintptr(0)) == 8 {
58+
if goarch.PtrSize == 8 {
5859
return uint64(hasher(abi.NoEscape(unsafe.Pointer(&v)), uintptr(s)))
5960
}
6061
lo := hasher(abi.NoEscape(unsafe.Pointer(&v)), uintptr(s))

0 commit comments

Comments
 (0)