From 01b8f5e8821eac0e3456d6200b351629fd3752f4 Mon Sep 17 00:00:00 2001 From: zhangyunhao Date: Tue, 19 Apr 2022 16:38:04 +0800 Subject: [PATCH] runtime: use fastrand64 in mapiterinit Change-Id: I5698c7576a0f39ae62de7bea64286ac8e578d421 Reviewed-on: https://go-review.googlesource.com/c/go/+/400916 Reviewed-by: Keith Randall Reviewed-by: Keith Randall Reviewed-by: Ian Lance Taylor Run-TryBot: Wayne Zuo TryBot-Result: Gopher Robot --- src/runtime/map.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/runtime/map.go b/src/runtime/map.go index e91b25eaec..2e513e2d52 100644 --- a/src/runtime/map.go +++ b/src/runtime/map.go @@ -842,9 +842,11 @@ func mapiterinit(t *maptype, h *hmap, it *hiter) { } // decide where to start - r := uintptr(fastrand()) + var r uintptr if h.B > 31-bucketCntBits { - r += uintptr(fastrand()) << 31 + r = uintptr(fastrand64()) + } else { + r = uintptr(fastrand()) } it.startBucket = r & bucketMask(h.B) it.offset = uint8(r >> h.B & (bucketCnt - 1))