From: zhangyunhao Date: Tue, 19 Apr 2022 06:20:29 +0000 (+0800) Subject: net: use fastrand64 in randInt X-Git-Tag: go1.19beta1~605 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a4bbcd4b1fc9dd40e0f86416d37bdd9e6d430f3f;p=gostls13.git net: use fastrand64 in randInt Change-Id: If3d8391d81e8de869dbb3c857f0570817e8aa440 Reviewed-on: https://go-review.googlesource.com/c/go/+/400914 Reviewed-by: Keith Randall Reviewed-by: Keith Randall Reviewed-by: Ian Lance Taylor Run-TryBot: Wayne Zuo TryBot-Result: Gopher Robot --- diff --git a/src/net/dnsclient.go b/src/net/dnsclient.go index a779c37e53..b609dbd468 100644 --- a/src/net/dnsclient.go +++ b/src/net/dnsclient.go @@ -13,13 +13,10 @@ import ( ) // provided by runtime -func fastrand() uint32 +func fastrandu() uint func randInt() int { - x, y := fastrand(), fastrand() // 32-bit halves - u := uint(x)<<31 ^ uint(int32(y)) // full uint, even on 64-bit systems; avoid 32-bit shift on 32-bit systems - i := int(u >> 1) // clear sign bit, even on 32-bit systems - return i + return int(fastrandu() >> 1) // clear sign bit } func randIntn(n int) int { diff --git a/src/runtime/stubs.go b/src/runtime/stubs.go index ca0cd1ba25..929f8fadca 100644 --- a/src/runtime/stubs.go +++ b/src/runtime/stubs.go @@ -199,8 +199,8 @@ func fastrandu() uint { //go:linkname sync_fastrandn sync.fastrandn func sync_fastrandn(n uint32) uint32 { return fastrandn(n) } -//go:linkname net_fastrand net.fastrand -func net_fastrand() uint32 { return fastrand() } +//go:linkname net_fastrandu net.fastrandu +func net_fastrandu() uint { return fastrandu() } //go:linkname os_fastrand os.fastrand func os_fastrand() uint32 { return fastrand() }