From c2d436dcfad64d5cc301cf05d446f7a93c19133e Mon Sep 17 00:00:00 2001 From: zhangyunhao Date: Tue, 19 Apr 2022 14:44:03 +0800 Subject: [PATCH] hash/maphash: use fastrand64 in MakeSeed Change-Id: I5ccbcea4c53658136b25ca608faec19eeec2e908 Reviewed-on: https://go-review.googlesource.com/c/go/+/400915 Reviewed-by: Keith Randall Reviewed-by: Keith Randall Reviewed-by: Ian Lance Taylor Run-TryBot: Wayne Zuo TryBot-Result: Gopher Robot --- src/hash/maphash/maphash.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/hash/maphash/maphash.go b/src/hash/maphash/maphash.go index 783690ea00..dfacd021db 100644 --- a/src/hash/maphash/maphash.go +++ b/src/hash/maphash/maphash.go @@ -252,21 +252,20 @@ func (h *Hash) Sum64() uint64 { // MakeSeed returns a new random seed. func MakeSeed() Seed { - var s1, s2 uint64 + var s uint64 for { - s1 = uint64(runtime_fastrand()) - s2 = uint64(runtime_fastrand()) + s = runtime_fastrand64() // We use seed 0 to indicate an uninitialized seed/hash, // so keep trying until we get a non-zero seed. - if s1|s2 != 0 { + if s != 0 { break } } - return Seed{s: s1<<32 + s2} + return Seed{s: s} } -//go:linkname runtime_fastrand runtime.fastrand -func runtime_fastrand() uint32 +//go:linkname runtime_fastrand64 runtime.fastrand64 +func runtime_fastrand64() uint64 func rthash(ptr *byte, len int, seed uint64) uint64 { if len == 0 {