]> Cypherpunks repositories - gostls13.git/commitdiff
net: use fastrand64 in randInt
authorzhangyunhao <zhangyunhao@bytedance.com>
Tue, 19 Apr 2022 06:20:29 +0000 (14:20 +0800)
committerKeith Randall <khr@golang.org>
Thu, 21 Apr 2022 17:46:26 +0000 (17:46 +0000)
Change-Id: If3d8391d81e8de869dbb3c857f0570817e8aa440
Reviewed-on: https://go-review.googlesource.com/c/go/+/400914
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/net/dnsclient.go
src/runtime/stubs.go

index a779c37e53df578e0651aff6c438048380046562..b609dbd468f698a7e80770866a0a423be5979fad 100644 (file)
@@ -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 {
index ca0cd1ba25eb1f69d6b21b76ccfb46016bf0be28..929f8fadca81aa065ca81d2c9b406113512e23d0 100644 (file)
@@ -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() }