]> Cypherpunks repositories - gostls13.git/commitdiff
hash/maphash: simplify pointer size checks
authorCherry Mui <cherryyz@google.com>
Thu, 21 Nov 2024 20:42:48 +0000 (15:42 -0500)
committerGopher Robot <gobot@golang.org>
Thu, 21 Nov 2024 21:15:24 +0000 (21:15 +0000)
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Cherry Mui <cherryyz@google.com>

src/hash/maphash/maphash_runtime.go

index 049aa6281d83819078b693c12d857b5e149ea562..3f049a99243a9ff415c9d544d2da803128bd23f2 100644 (file)
@@ -8,6 +8,7 @@ package maphash
 
 import (
        "internal/abi"
+       "internal/goarch"
        "internal/goexperiment"
        "unsafe"
 )
@@ -27,7 +28,7 @@ func rthash(buf []byte, seed uint64) uint64 {
        // The runtime hasher only works on uintptr. For 64-bit
        // architectures, we use the hasher directly. Otherwise,
        // we use two parallel hashers on the lower and upper 32 bits.
-       if unsafe.Sizeof(uintptr(0)) == 8 {
+       if goarch.PtrSize == 8 {
                return uint64(runtime_memhash(unsafe.Pointer(&buf[0]), uintptr(seed), uintptr(len)))
        }
        lo := runtime_memhash(unsafe.Pointer(&buf[0]), uintptr(seed), uintptr(len))
@@ -54,7 +55,7 @@ func comparableHash[T comparable](v T, seed Seed) uint64 {
        } else {
                hasher = (*abi.OldMapType)(unsafe.Pointer(mTyp)).Hasher
        }
-       if unsafe.Sizeof(uintptr(0)) == 8 {
+       if goarch.PtrSize == 8 {
                return uint64(hasher(abi.NoEscape(unsafe.Pointer(&v)), uintptr(s)))
        }
        lo := hasher(abi.NoEscape(unsafe.Pointer(&v)), uintptr(s))