Commit fd5540e7 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

runtime: tighten select permutation generation

This is the optimization made to math/rand in CL 21030043.

Change-Id: I231b24fa77cac1fe74ba887db76313b5efaab3e8
Reviewed-on: https://go-review.googlesource.com/9269Reviewed-by: default avatarMinux Ma <minux@golang.org>
parent 3787950a
...@@ -244,13 +244,9 @@ func selectgoImpl(sel *hselect) (uintptr, uint16) { ...@@ -244,13 +244,9 @@ func selectgoImpl(sel *hselect) (uintptr, uint16) {
pollslice := slice{unsafe.Pointer(sel.pollorder), int(sel.ncase), int(sel.ncase)} pollslice := slice{unsafe.Pointer(sel.pollorder), int(sel.ncase), int(sel.ncase)}
pollorder := *(*[]uint16)(unsafe.Pointer(&pollslice)) pollorder := *(*[]uint16)(unsafe.Pointer(&pollslice))
for i := 0; i < int(sel.ncase); i++ { for i := 0; i < int(sel.ncase); i++ {
pollorder[i] = uint16(i)
}
for i := 1; i < int(sel.ncase); i++ {
o := pollorder[i]
j := int(fastrand1()) % (i + 1) j := int(fastrand1()) % (i + 1)
pollorder[i] = pollorder[j] pollorder[i] = pollorder[j]
pollorder[j] = o pollorder[j] = uint16(i)
} }
// sort the cases by Hchan address to get the locking order. // sort the cases by Hchan address to get the locking order.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment